[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-general
Subject:    [PHP] socket gives notice on server side(simple newbie code)
From:       Negin Nickparsa <nickparsa () gmail ! com>
Date:       2014-08-20 2:48:39
Message-ID: CAJGV41c3zJqZhix6dt4KVaYB8PRT0Kc74dy=MBOAeB=Hf489fQ () mail ! gmail ! com
[Download RAW message or body]


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


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic