I want to realize a simple client-server connection using Nodejs. But I\'ve encountered with the following problem.
Consider the code
server.js:
TCP is a stream protocol. Single write
on one end of the pipe can result in multiple "reads" on the other end, and the other way around. You have to either explicitly tell the other side how many bytes you are sending by including the length in the message; or provide easily recognizable message delimiters. In any case you need to read in a loop.