dlublink Posted July 8, 2010 Share Posted July 8, 2010 Using the example on this page : http://ca3.php.net/stream_socket_server <?php $socket = stream_socket_server("udp://127.0.0.1:1113", $errno, $errstr, STREAM_SERVER_BIND); if (!$socket) { die("$errstr ($errno)"); } do { $pkt = stream_socket_recvfrom($socket, 1, 0, $peer); echo "$peer\n"; stream_socket_sendto($socket, date("D M j H:i:s Y\r\n"), 0, $peer); } while ($pkt !== false); ?> If the message is sent from the same subnet, this script works fine, I see the output of the message. But if the message is from a remote system ( different subnet ), the script does nothing, even though I see the UDP packet coming in using ngrep. Is there some kind of IP restriction in effect? It does this to me on PHP 5.3 and PHP 5.2.6, running on Ubuntu 10.04, Ubuntu 8.04 and Ubuntu 7.04. The only thing I changed when I copied the script is I replaced "127.0.0.1" with my public IP address. ( not 10.x.x.x, 192.168.x.x or 172..., a proper unnatted public IP ) Any ideas what might cause the message not to be received? Thanks, David Link to comment https://forums.phpfreaks.com/topic/207185-problem-receiving-messages-from-other-subnets-using-stream_socket_server/ Share on other sites More sharing options...
dlublink Posted July 9, 2010 Author Share Posted July 9, 2010 I think the problem might be OS related, because when it is sent from Ubuntu 10.04 to Ubuntu 10.04 it works fine, from Ubuntu (7|.04 to 8.04 it works fine. But between the two, it doesn't work. I am going to see if I can find a difference in the actual packets Link to comment https://forums.phpfreaks.com/topic/207185-problem-receiving-messages-from-other-subnets-using-stream_socket_server/#findComment-1083324 Share on other sites More sharing options...
dlublink Posted July 9, 2010 Author Share Posted July 9, 2010 After doing some packet sniffing, I found no difference ( other than the IP ) between the two packets. I did notice however that if the local PHP script was NOT running, an ICMP packet was being sent out saying the port was not available. Funny enough, it was only being sent in reply to the server that PHP can receive the UDP packets from. So I think the bug might be in the actual sending of the packets. But I use the same server to send UDP packets to Kamailio datagram MI interface with no problem. So why would it work with Kamailio but not with PHP ? I am using the code the same code on both machines. Here is the test code to send it ( it's a PHP.net example + while loop ) : $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); $msg = "Ping !"; $len = strlen($msg); while ( socket_sendto($sock, $msg, $len, 0, 'my.cool.ip.is.hidden.here', 5000 ) ) sleep(1); Link to comment https://forums.phpfreaks.com/topic/207185-problem-receiving-messages-from-other-subnets-using-stream_socket_server/#findComment-1083595 Share on other sites More sharing options...
dlublink Posted July 9, 2010 Author Share Posted July 9, 2010 I setup a daemon using xinetd, and the received packets are doing the same thing. So the problem seems to be with the packets being sent. Link to comment https://forums.phpfreaks.com/topic/207185-problem-receiving-messages-from-other-subnets-using-stream_socket_server/#findComment-1083630 Share on other sites More sharing options...
dlublink Posted July 9, 2010 Author Share Posted July 9, 2010 I installed PHP 5.2.4 on Ubuntu 10.04, and the packets go through anyway. It would seem the issue is OS related. Link to comment https://forums.phpfreaks.com/topic/207185-problem-receiving-messages-from-other-subnets-using-stream_socket_server/#findComment-1083644 Share on other sites More sharing options...
dlublink Posted July 9, 2010 Author Share Posted July 9, 2010 Ok, so after a day of frustrations, I did the following test : On Ubuntu 8.04 : nc mycoolip 5000 -u On Ubuntu 10.04 : nc mycoolip 5000 -u On ( another ) Ubuntu 10.04 : nc 5000 -u -l Messages sent from 10.04 appear on the listening nc, and from 8.04 do not. Therefore this issue is NOT PHP related. I'll post back if I ever figure out why this isn't working. Link to comment https://forums.phpfreaks.com/topic/207185-problem-receiving-messages-from-other-subnets-using-stream_socket_server/#findComment-1083665 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.