[Webinar] Streamline your web hosting managementRegister Today


I need to send an organized byte array via tcp/udp

Posted on 2006-04-24
Medium Priority
Last Modified: 2012-06-21
I need to send an organized byte array via tcp/udp.

Here is the problem:

Dim sendBytes() As Byte = Encoding.ASCII.GetBytes(Data1.Text & Data2.Text)

This is just a test. But you see how I have to merge the Data1 & Data2 together?  Then the server would receive it and I would have to parse them.  Instead of doing that is there an organized way to send a byte array in the form of a structure?

Private structure organizedPacket
   Dim Data1 as string
   Dim Data2 as string
End Structure

Dim UDPPAcket as new organizedPacket
udppacket.data1 = "hello"
udppacket.data2 = "world"

UDP.send(udppacket, udppacket.Length)

Examples in VB.NET would be great. Thanks experts.

Question by:Hepen
  • 4
LVL 16

Expert Comment

ID: 16539114
Are you hosting or consuming a web service or using remoting?
LVL 16

Expert Comment

ID: 16539120

Author Comment

ID: 16539715
RobertRFreeman: I am using a normal vb.net windows application which acts as a UDPClient then I have another seperate vb.net windows application that acts as a UDP server (which uses uspclient).  I'm just sending a byte array across the network to the server but I just wanted to be able to send organized structures.

Do you have a vb.net example hanging around with UDP client/server using serialization?
LVL 16

Accepted Solution

RobertRFreeman earned 2000 total points
ID: 16544461
LVL 16

Expert Comment

ID: 16544660
This article explains how to use BinaryFormatter with a MemoryStream to do what you want.

Usually you would use a NetworkStream, but UDP wont support a Stream, so you need to write to a MemoryStream to get the byte array to send directly.

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This video tutorial shows you the steps to go through to set up what I believe to be the best email app on the android platform to read Exchange mail.  Get the app on your phone: The first step is to make sure you have the Samsung Email app on your …
Get the source code for a fully functional Access application shell with several popular security features that Access VBA application developers desire, but find difficult or impossible to figure out how to code. You get the source code for managi…
Suggested Courses
Course of the Month7 days, 19 hours left to enroll

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question