SDII_Davis Posted May 9, 2011 Share Posted May 9, 2011 Hi! I am having trouble reading a stream of data being sent to my PC via PHP5. It seems that my code stops when it gets to the read section and just sits there indefinately. I am somewhat new to PHP so a solution and explanation would be great! <?php $host = "129.000.00.01"; // host IP address $port = 40000; // port to listen to // sets script execution limit set_time_limit(30); // 0 means unlimited execution time (constant running) // create UDP socket $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP) or die("Could not create UDP socket!\n"); // reset socket for binding if(!socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1)) { echo "Failed to reset socket!\n"; } else echo "Reset socket successfully!\n"; // bind socket socket_bind($socket, $host, $port); // connect if (!socket_connect($socket, $host, $port)) { echo "Failed to connect to port!\n"; } else echo "Connected to port successfully!\n"; while (1) { echo socket_read($socket, 1024, PHP_NORMAL_READ)."\n"; } // close sockets socket_close($socket); echo "\nDone"; Quote Link to comment https://forums.phpfreaks.com/topic/235954-read-a-udp-stream-of-data/ Share on other sites More sharing options...
SDII_Davis Posted May 9, 2011 Author Share Posted May 9, 2011 bump Quote Link to comment https://forums.phpfreaks.com/topic/235954-read-a-udp-stream-of-data/#findComment-1212978 Share on other sites More sharing options...
SDII_Davis Posted May 9, 2011 Author Share Posted May 9, 2011 bump Quote Link to comment https://forums.phpfreaks.com/topic/235954-read-a-udp-stream-of-data/#findComment-1212989 Share on other sites More sharing options...
SDII_Davis Posted May 9, 2011 Author Share Posted May 9, 2011 bump Quote Link to comment https://forums.phpfreaks.com/topic/235954-read-a-udp-stream-of-data/#findComment-1212999 Share on other sites More sharing options...
SDII_Davis Posted May 9, 2011 Author Share Posted May 9, 2011 bump Quote Link to comment https://forums.phpfreaks.com/topic/235954-read-a-udp-stream-of-data/#findComment-1213001 Share on other sites More sharing options...
mikosiko Posted May 9, 2011 Share Posted May 9, 2011 you better read here and here... just saying Quote Link to comment https://forums.phpfreaks.com/topic/235954-read-a-udp-stream-of-data/#findComment-1213013 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.