why is an integer type sent upside down?

117 views Asked by At

I am making a server program and a client have sent various data like string, integer.

when a client program sent me string, I recieved in regular sequence.

for example,

a client sent me "hello" I have recieved h e l l o \0

However, a client sent me integer like 12345 I received upside down.

for example)

a client wants to send me 12345(integer type) he or she sent '30''39''\0' and I recieved '57''48''\0' ('57' is dec of '0x39' and '48' is dec of '0x30')

I found that the value was sent upside down and I thought that was because of network byte order. However, I didn't use network and I had client and server program. In other word, I sent myself data and my computer is not connected with internet.

I communicate with a client by using a mail slot in c language. why was integer type sent upside down?

1

There are 1 answers

0
Bran On

The socket-related functions use big-endian to store your integers for some functions. You'll have to translate them with the available functions, or you can write your own macros to do it, which isn't difficult.