tags:

views:

1174

answers:

1

The hosting service that I use currently does let me use sockets, probably for good reason on their part. They do, however, let me use fsockopen. I was wondering what the difference is, because some scripts that worked with socket_create and even stream_socket_server, do not work with fsockopen. That said, if fsockopen should work, my code is listed below. What it does is it listens on its own ip address for incoming udp packets and reads them.

Thanks

$sock = fsockopen("udp://x.x.x.x", $port);
while(1)
{
    $buf = fread($sock, 200);
    flush();
    ob_flush();
}
+2  A: 

fsockopen creates a connection to a host, not a listening socket.

fsockopen($address) ~== socket_connect(socket_create(), $address)

Your hosting provider doesn't want you listening on alternate ports/protocols.

If what you have works, I wouldn't count on it always working as it would be a bug.

Ryan Graham
thanks "fsockopen == socket_connect(socket_create(), $address)" was exactly what i was looking for. looks like i need to find a new host : P
Samuel