473,695 Members | 2,688 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(0 x02).chr(0x03). chr(0x00).chr(0 xA0);
$binary_msg_siz e = 5;

Initially, I tried using
$fp = fsockopen("udp://" . $server,$port,$ errno,$errstr)
and
fwrite($fp,$bin ary_msg,$binary _msg_size)

Since this didn't work, I then tried
$sock = socket_create(A F_INET,SOCK_DGR AM,SOL_UDP);
and
socket_sendto($ sock,$binary_ms g,$binary_msg_s ize,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 14524
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(0 x1d).... 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********@hot mail.com> wrote in message
news:ac******** *************** ***@posting.goo gle.com...
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(0 x02).chr(0x03). chr(0x00).chr(0 xA0);
$binary_msg_siz e = 5;

Initially, I tried using
$fp = fsockopen("udp://" . $server,$port,$ errno,$errstr)
and
fwrite($fp,$bin ary_msg,$binary _msg_size)

Since this didn't work, I then tried
$sock = socket_create(A F_INET,SOCK_DGR AM,SOL_UDP);
and
socket_sendto($ sock,$binary_ms g,$binary_msg_s ize,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
4870
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 action="200.120...../file.php" method="POST" enctype="multipart/form-data"> <form name="file" /> <form name="ip_01" />
5
6721
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 output, but since cout and printf convert LF line endings to CRLF (I'm on Windows), the resulting image ends up being corrupt. Is there ANY way to get around this? It seems writing CGI scripts in C++ on Windows is pretty much impossible. Here's an...
4
4226
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. I need to be able to print shipping labels from a web page within this application. The shipping label data is pulled from a 3rd party application and comes in binary format specific for certain brands of label printers. I have a class library...
9
18012
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 ;) My problem now, is that I need to send certain binary data over a socket. That is, I want to make some bytes, and stuff them in a TCP packet, send them down the pipe, and then listen for a response. socket.send, as best I can tell, will only...
9
4919
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 strReturnData As String = _ System.Text.Encoding.ASCII.GetString(receiveBytes)
3
4299
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 receiver is running within Process1. If I move the receiver into Process2 then its fast. Please can someone explain.
4
3736
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 the receiver, who unpickles the data and uses it. So far this has been working fine, but I now need a way of separating multiple chunks of pickled binary data in the stream being sent back and forth. Questions:
1
15079
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 protocol. There are a few open source programs that do this already (http://romraider.com/ , http://jdash.sourceforge.net/ , http://tari.co.za/downloads/software/source/ ), but they are written in Java or C++. I have never done anything with serial...
20
9421
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, just as a string) then for each file to be send: 2. Length of Filename (again as a string) 3. Filename 4. File as binary data.
0
8649
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9004
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8864
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8838
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7683
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6506
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5842
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4592
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2289
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.