By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,934 Members | 1,692 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,934 IT Pros & Developers. It's quick & easy.

sending binary data via UDP

P: n/a
I'm trying to send a packet of binary data to a UDP server. If I send
a text string, it works fine. If I attempt to send binary data, it
sends a UDP packet with 0 bytes of data (just the headers). I can see
this because I'm running Ethereal and watching the packets.

I'm defining the packets as shown below:

$text_msg = "Hello, world\r\n";
$binary_msg = chr(0x01).chr(0x02).chr(0x03).chr(0x00).chr(0xA0);
$binary_msg_size = 5;

Initially, I tried using
$fp = fsockopen("udp://" . $server,$port,$errno,$errstr)
and
fwrite($fp,$binary_msg,$binary_msg_size)

Since this didn't work, I then tried
$sock = socket_create(AF_INET,SOCK_DGRAM,SOL_UDP);
and
socket_sendto($sock,$binary_msg,$binary_msg_size,0 ,$server,$port);

For both methods, sending $text_msg worked, but sending $binary_msg
resulted in a UDP packet with 0 data bytes being sent.

I've found examples of sending binary data, but they used TCP, and
I've found examples of sending UDP, but they send text strings.

Anyone have experience with sending binary data to a UDP server?
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
As it turns out, the reason I was getting zero data bytes in my UDP packet
was that I had declared the packet variable outside the function in which I
was using it.

$packet = chr(0x01).chr(0x1d).... etc

function doSomething($x)
{
// using $packet in here gives you an empty variable.
}

So I guess it was a very basic PHP language thing I was running into. Guess
I've done too much Perl and assumed the variables were accessible in the
function. :-)
"coder_1024" <co********@hotmail.com> wrote in message
news:ac**************************@posting.google.c om...
I'm trying to send a packet of binary data to a UDP server. If I send
a text string, it works fine. If I attempt to send binary data, it
sends a UDP packet with 0 bytes of data (just the headers). I can see
this because I'm running Ethereal and watching the packets.

I'm defining the packets as shown below:

$text_msg = "Hello, world\r\n";
$binary_msg = chr(0x01).chr(0x02).chr(0x03).chr(0x00).chr(0xA0);
$binary_msg_size = 5;

Initially, I tried using
$fp = fsockopen("udp://" . $server,$port,$errno,$errstr)
and
fwrite($fp,$binary_msg,$binary_msg_size)

Since this didn't work, I then tried
$sock = socket_create(AF_INET,SOCK_DGRAM,SOL_UDP);
and
socket_sendto($sock,$binary_msg,$binary_msg_size,0 ,$server,$port);

For both methods, sending $text_msg worked, but sending $binary_msg
resulted in a UDP packet with 0 data bytes being sent.

I've found examples of sending binary data, but they used TCP, and
I've found examples of sending UDP, but they send text strings.

Anyone have experience with sending binary data to a UDP server?

Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.