binary data over UDP with PHP?
| From: | coder_1024 | Date: | Wed, 07 Jul 2004 23:23:48 +0000 |
| Subject: | binary data over UDP with PHP? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-189921@lists.php.net to get a copy of this message | ||
I'm trying to send some binary data to a UDP server using PHP. The examples
I've been able to find show sending binary data over TCP, or they show
sending text over UDP.
I'm constructing the messages using the below:
$text_msg = "Hello, World\r\n";
$binary_msg = chr(0x01).chr(0x02).chr(0x00).chr(0xAD);
$binary_msg_size = 4;
I've tried a couple methods of sending the data:
$fp = fsockopen("udp://" . $host,$port,....);
fwrite($fp,$binary_msg,$binary_msg_size);
and
$sock = socket_create(AF_INET,SOCK_DGRAM,SOL_UDP);
socket_sendto($sock,$binary_msg,$binary_msg_size,0,$host,$port);
In either case, a UDP packet is sent, but with a zero data size. If I
instead send the $text_msg, it works as expected. For some reason sending
the binary data doesn't work.
Does anyone have insight into how to send binary data over UDP using PHP?