Jump to content

Socket_read() not getting anything


miseleigh

Recommended Posts

I'm using UDP sockets to talk to an Ether IO 24 board, and I need to make my commands get through properly, so I'm trying to read back the data I send to it.  However, I'm not getting anything, and instead my browser just hangs.  I don't know much about sockets (this is my first time using them) so maybe there's something I should be doing that I'm not or vice versa.  Any help would be greatly appreciated.

 

set_time_limit(0);
$socket = socket_create(AF_INET, SOCK_DGRAM, 0);
$result = socket_connect($sock, $IP, $Port);

$cmd = pack("ci", $writeA, $xff);    // writes to device - this works
socket_write($sock, $cmd);
$cmd = pack("c", $readA);    // tells device to send data back
socket_write($sock, $cmd);

$buf=socket_read($sock, 2);    // I get nothing here
echo $buf;

Link to comment
https://forums.phpfreaks.com/topic/97132-socket_read-not-getting-anything/
Share on other sites

Whoops, I had a typo in there, but it really does all work up to the read() call:

$sock = socket_create(AF_INET, SOCK_DGRAM, 0);

 

One possibility I've thought of is that the Ether doesn't know where to send its data back to.  Is there a way to listen to a specific ip address & port number, since I have no way of telling the Ether who's talking to it?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.