473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

sending binary data via UDP

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
1 14459
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ot?vio | last post by:
Hi! I'm havin a problem about sending a binary file with fsockopen. My problem is solved when i do: -------------------->8------CODE----------------------------- <form...
5
by: gof | last post by:
I'm pretty new to C++, and this seemingly simple thing is driving me crazy. I'm trying to write a CGI script to serve images on the fly. CGI requires the content to be sent through standard...
4
by: Schwarty | last post by:
I hope I posted this to the correct group. If not, please let me know and I will get it posted in the correct section. I have a web application developed in ASP.NET using C# for the code behind....
9
by: thorley | last post by:
Greetings, since there was no reponse to my previous post about an existing FastCGI server in python, I've taken to writing my own. (which of course I'll share--*if* there's something to share ;) ...
9
by: Miro | last post by:
VB 2003 at the end of the code, this works great. bytCommand = Encoding.ASCII.GetBytes("testing hello send text") udpClient.Send(bytCommand, bytCommand.Length) and this recieves it Dim...
3
by: BuddyWork | last post by:
Hello, Could someone please explain why the Socket.Send is slow to send to the same process it sending from. Eg. Process1 calls Socket.Send which sends to the same IP address and port, the...
4
by: David Hirschfield | last post by:
I have a pair of programs which trade python data back and forth by pickling up lists of objects on one side (using pickle.HIGHEST_PROTOCOL), and sending that data over a TCP socket connection to...
1
by: Rich | last post by:
Hello, I am working on a python library for sending and receiving data from a Subaru's ECU (the fuel injection computer) via the OBD-II port and an OBD to USB cable, with the Subaru Select Monitor...
20
by: tomPee | last post by:
Hi, I've bumbed into a slight problem now, and I just don't seem to know how to fix it. What I want to do is the following: Send over a socket: 1. Number of files to be send (not as an integer,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.