Trouble reading created sockets (php) -
i pretty new how sockets work. in learning process there things i'm not able understand no matter how search.
i made simple script today:
<?php $ip = gethostbyname(gethostname()); //get ip of machine $address = $ip; $port = 34242; echo "starting data processing server...\n"; $socket = socket_create(af_unix, sock_stream, 0); if($socket === false){ echo "socket failed connect.\n"; exit(1); } socket_set_nonblock($socket); $stopped = false; $lastread = microtime(true); while($data = socket_read($socket, 4) && !$stopped){ $lastread = microtime(true); } echo("closing data processing server, bye!\n"); ?>
now when run in console (local host) error:
warning: socket_read(): unable read socket [57]: socket not connected in /users/***/desktop/sockt.php on line 22
what doing wrong? intensions create socket data can funneled through give clients.
you need socket_connect, create not enough (that's setting stuff)
you needed neither $address
nor $port
. ;o)
Comments
Post a Comment