Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Broken Messages in a socket buffer  RSS feed

 
Sameer Amte
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I have a streaming socket that receives data from the Server. The server does not pass any header data with the message i.e., the number of bytes of data in each message. Hence I am reading the data into a fixed length buffer. There is always a chance that the buffer might contain more than one message. If it contains more than one complete message in one read I can handle it but there is also a chance that the message might be broken. eg. read say 20 bytes and the buffer contains message1message2mess. Is there any standard approach I can take to handle these broken messages?

Thanks
Sameer
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without a length, how do you identify the end of msg1 and the beginning of msg2? If you have a delimiter or something, I think I've done something like this.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!