Click here to Skip to main content
15,888,097 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello

I want to send a data to the printer via udp port. I have a structure of that udp packet but have no idea how to build it.

The structure

Does anyone have an idea?

What I have tried:

UdpClient udpClient = new UdpClient();
            udpClient.Connect("192.168.0.99", 47545);
            Byte[] senddata = Encoding.ASCII.GetBytes("id_val_operation_acquire_records2");
            udpClient.Send(senddata, senddata.Length);
Posted
Updated 8-Mar-17 3:42am

1 solution

Create a C# structure that corresponds to the structure definition. This structure must not contain padding bytes (Pack = 1) and use members with fixed width (use byte, UInt16, UInt32 according to the length of the fields). See StructLayoutAttribute.Pack Field (System.Runtime.InteropServices)[^].

Then create an instance of this structure, fill it, and send it. Sending requires converting the structure to a byte array which is a common task; just search for "c# structure to byte array".
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900