Create Binary data format for use in TCPIP socket project

ballybeg

Member
Joined
Jul 28, 2011
Messages
20
Location
Canberra Australia
Programming Experience
10+
Hey all,

I am working on a project that requires data transfer using TCPIP sockets. I am using a 3rd party Library (Ostrosoft) that handles the
wsock32.dll api calls.

The project calls for the creation of a header that logs into a user account. Here is the header:

NameLengthFormatValue
Marker4Binary4,275,878,552
MSN2Binary0
Message Type2Binary4096
Message Length2Binary54
Action Code2Binary4096
Error Code2Binary0



In hex the result looks like this:

Header HEX

Start marker <4275878552> FE DC BA 98
MSN <0> 00 00

Message type <4096> 10 00

Message length <54> 00 36

Action code <4096> 10 00

Error code <0> 00 00


My questions are:

1) If I define the marker (value 4,275,878,552) what data type should it be
2) What function do I use to convert the values into a binary format?

The final complication is message has to be submitted in network byte order! How do I do that?

Assistance greatly appreciated.

ballybeg
 
You can use the BitConverter class to convert between Byte arrays and numbers and a derived Encoding object to convert between Byte arrays and text. If a number is 4 bytes (32 bits) then it should be type Integer and if it's 2 bytes (16 bits) then it should be type Short.
 
Back
Top