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

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.

HepenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RobertRFreemanCommented:
Are you hosting or consuming a web service or using remoting?
0
RobertRFreemanCommented:
0
HepenAuthor Commented:
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?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RobertRFreemanCommented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.