socket gives notice on server side(simple newbie code)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux