Jump to content

Recommended Posts

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";

Link to comment
https://forums.phpfreaks.com/topic/235954-read-a-udp-stream-of-data/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.