Re: garbled long value returned from the network

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



<family.sens@xxxxxxxxx> wrote:
im using a C# webservice to communicate some data over a socket to a
VC++ program.

what the vc++ program does is return a struct() over the socket.

now the struct contains 2 32 bit integers (according to VC++) i.e. long
(System.Int32)

Note that a long may be 32 bits in C (in some compilers anyway) but in
C# an int is 32 bits and a long is 64.

all the byte[] data is received correctly, however , if im expecting
'320' as the value of the long variable im getting a huge number like
'612334539'.

does this have something to do with Little-Endian / Big-Endian issues ?

Sounds like it.

does this require me to use IPAddress.NetworkToHostOrder() ?

No. You can use my EndianBitConverter, available at
http://www.pobox.com/~skeet/csharp/miscutil

That lets you convert in either endianness. (There's an equivalent
EndianBinaryReader/Writer, too.)

--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
.