C# order of bytes sent and received by socket -
i wondering order of sent , received bytes by/from tcp socket.
i got implemented socket, it's , working, that's good. have called "a message" - it's byte array contains string (serialized bytes) , 2 integers (converted bytes). has - project specifications :/
anyway, wondering how working on bytes: in byte array, have order of bytes - 0,1,2,... length-1. sit in memory.
how sent? last 1 first send? or first? receiving, think, quite easy - first byte appear gets on first free place in buffer.
i think little image made nicely shows mean.
they sent in same order present in memory. doing otherwise more complex... how if had continuous stream of bytes? wait last 1 has been sent , reverse all? or inversion should work "packet packet"? each block of 2k bytes (or whatever size of tcp packets) internally reversed order of packets "correct"?
receiving, think, quite easy - first byte appear gets on first free place in buffer.
why on earth sender should reverse bytes receiver shouldn't? if build symmetric system, both action or none it!
note real problem 1 of endianness. memory layout of int
on computer different layout of int
of computer. 1 of 2 computers have reverse 4 bytes of int
. endianness resolved "primitive type" "primitive type". many internet protocols, historical reason, big endian, while intel cpus little endians. internal fields of tcp big endian (see big endian or little endian on net?), here speaking of fields of tcp, not of data moved tcp protocol.
Comments
Post a Comment