Greetings all. I've been working on a project dealing with sockets and sending out some kind of broadcast message. I have used many various methods and I am able to send out a broadcast and I can see the responses being sent, however, I am never able to retrieve the responses with any socket read functions.
I've tried the fsockopen() method, using fwrite/fputs and fread/fgets, as well as the socket_write and socket_read methods. Since I am using UDP I recently decided to try to use socket_sendmsg and socket_sendto. With sendto() I am able to send the message out but I am still unable to get any responses using recvfrom. I also have a hard time running the UDP examples on the PHP site, and it seems that everything is configured correctly. I am currently running PHP 4.3.6. I know the newer .7 version was released yesterday, but haven't gotten around to trying it out on it yet.
Basically what I've been doing is something like:
<?php
$buf = "this will be the broadcast message";
$socket = fsockopen('udp://255.255.255.255', $port, $errno, $errstr) or die ("Error creating socket");
fwrite($socket, $buf); // this works fine when i check ports with a scan utility, I can see the responses.
// I generally set the sockets to blocking at this point since it will hang indefinitly.
fread($socket, 80); // will hang here since nothing is being returned to the buffer.
// I can see error responses being sent to those devices that are
// sending me the initial response, saying the destination can not be reached.
fclose($socket);
?>
This isn't my actual code at the moment and I haven't been using the fsockopen() method, but in all cases I am unable to get a response back. By watching the ports, as I've said, I can see the responses are unable to make it back to my destination. But they show up as making it to the computer, and the actual computer IP responding back, and not a router IP.
All I'm trying to do at this point is successfully read the responses sent back to me in a very basic form.
Sorry the post isn't too elaborate I don't have the code on me at the moment to reference to. Any ideas from anyone?
Thanks.