[Gllug] OT: reading from a socket in php
salsaman at xs4all.nl
salsaman at xs4all.nl
Wed Oct 6 02:36:42 UTC 2010
Hi all,
I am trying to write a simple php application which reads from udp port
9998/localhost. I know the data is being sent, but php never receives
anything.
The code i am trying is something like:
function get_response($status_sock)
{
do {
// tried also with PHP_NORMAL_READ
$recv = socket_read($status_sock, '1024',PHP_BINARY_READ);
// i have also tried:
//$from='';
//$port=0;
// socket_recvfrom($status_sock,$recv,1,0,$from,$port);
// tried also with socket_read()
if ($recv != "") {
// never reaches here...
echo("got $recv\n");
return;
}
usleep(10000);
} while ($recv=="");
}
if(($status_sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP)) < 0) {
echo "Could not create status socket.\n";
}
if (!socket_connect($status_sock,"127.0.0.1",9998)) {
echo "Could not connect";
}
get_response($status_sock);
socket_close($status_sock);
Why am I not receiveing any data in the socket ?
Salsaman.
--
Gllug mailing list - Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug
More information about the GLLUG
mailing list