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:

[TABLE="class: cms_table, width: 562"]
[TR]
[TH]Name[/TH]

[TH]Length[/TH]

[TH]Format[/TH]

[TH]Value[/TH]

[/TR]

[TR]
[TD]Marker[/TD]

[TD]4[/TD]

[TD]Binary[/TD]

[TD]4,275,878,552[/TD]

[/TR]

[TR]
[TD]MSN[/TD]

[TD]2[/TD]

[TD]Binary[/TD]

[TD]0[/TD]

[/TR]

[TR]
[TD]Message Type[/TD]

[TD]2[/TD]

[TD]Binary[/TD]

[TD]4096[/TD]

[/TR]

[TR]
[TD]Message Length[/TD]

[TD]2[/TD]

[TD]Binary[/TD]

[TD]54[/TD]

[/TR]

[TR]
[TD]Action Code[/TD]

[TD]2[/TD]

[TD]Binary[/TD]

[TD]4096[/TD]

[/TR]

[TR]
[TD]Error Code[/TD]

[TD]2[/TD]

[TD]Binary[/TD]

[TD]0[/TD]

[/TR]

[/TABLE]



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