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

Posted on 2006-04-24
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
    LVL 16

    Expert Comment

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

    Expert Comment


    Author Comment

    RobertRFreeman: I am using a normal windows application which acts as a UDPClient then I have another seperate 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 example hanging around with UDP client/server using serialization?
    LVL 16

    Accepted Solution

    LVL 16

    Expert Comment

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
    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…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    758 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now