Nodejs streaming

后端 未结 2 1084
你的背包
你的背包 2021-02-19 10:46

I want to realize a simple client-server connection using Nodejs. But I\'ve encountered with the following problem.

Consider the code

server.js:

         


        
2条回答
  •  温柔的废话
    2021-02-19 11:39

    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.

提交回复
热议问题