networking - Handling messages over TCP -


i'm trying send , receive messages on tcp using size of each message appended before starts.

say, first 3 bytes length , later message:

as small example:

005hello003hey002hi 

i'll using method large messages, because buffer size constant integer say, 200 bytes. so, there chance complete message may not received e.g. instead of 005hello 005he nor complete length may received e.g. 2 bytes of length in message.

so, on problem, i'll need wait next message , append incomplete message etc.

my question is: 1 having these difficulties appending messages each other, appending lengths etc.. make them complete or usually how need handle individual messages on tcp? or, if there better way?

what you're seeing 100% normal tcp behavior. expected you'll loop receiving bytes until "message" (whatever means in context). it's part of work of going low-level tcp byte stream higher-level concept "message".

and "usr" right above. there higher level abstractions may have available. if they're appropriate, use them avoid reinventing wheel.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -