Re: socket gives notice on server side(simple newbie code)
| From: | Negin Nickparsa | Date: | Wed, 20 Aug 2014 02:50:10 +0000 |
| Subject: | Re: socket gives notice on server side(simple newbie code) | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-323747@lists.php.net to get a copy of this message | ||
Sincerely
Negin Nickparsa
On Tue, Aug 19, 2014 at 7:48 PM, Negin Nickparsa <nickparsa@gmail.com>
wrote:
> I am struggling with my code and I cannot figure out what I have done
> which it tells me Notice
>
> here is my server.php:
>
> <?php
> set_time_limit(0);
>
> $stock=array("hi"=>"hi","name"=>"negin","question"=>"answer");
> $address="127.0.0.1";
> $port="127";
> $sock= socket_create(AF_INET,SOCK_STREAM, getprotobyname("tcp"));
> socket_bind($sock, $address,$port);
> socket_listen($sock);
> $client= socket_accept($sock);
> $input=socket_read($client, 1024);
> echo "you entered ".$input;
> if($stock[$input]!=NULL)
> {
> $answer=$stock[$input];
> socket_write($sock,$answer, $port);
>
> }
> else{
> echo socket_strerror(0);
> }
> socket_close($sock);
> ?>
>
> and here is my client.php:
>
> <?php
> $address="127.0.0.1";
> $port="127";
> $sock= socket_create(AF_INET,SOCK_STREAM, getprotobyname("tcp"));
> echo "enter your data:";
> $input= fgets(STDIN);
> socket_connect($sock, $address,$port);
> socket_write($sock,$input ,strlen($input));
> $dt=socket_read($sock, 1024);
> echo $dt;
> ?>
>
> I really cannot undrestand why the output is this on server side:
>
> c:\wamp\www\phpzend>php -f server.php
> you entered salam
>
> Notice: Undefined index: salam
> in C:\wamp\www\phpzend\server.php on line 12
>
> Call Stack:
> 0.0010 232328 1. {main}() C:\wamp\www\phpzend\server.php:0
>
> The operation completed successfully.
>
> but it doesn't write on my client side so this notice completely is a big
> issue I var_dumped the $input and it is string I have no idea what's wrong
> here
>
sorry I changed the array content which was persian it was like this
before:
$stock=array("salam"=>"salam","esmet
chie"=>"negin","chika mikoni"=>"socket
minevisam!");