Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi
I'm trying to implement a client/server protocol buffer stream.
When using tcp/ip the issue is to know where a message end and a new message begin.
The solution is to implement length-prefix messaging system.
Is there a way to send message-length + message at the same time through a socket??
Any code snippets would be appreciated ^^
thx in advance.
Posted

1 solution

Just add the message length to the beginning of your message as an integer value (don't forget to convert it via htonl()[^]. You could also send this value independently of your actual text and let the receiver re-assemble it when handling the input messages.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900