Nodejs streaming

后端 未结 2 1090
你的背包
你的背包 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:48

    use socket.write return value and callback as documented here https://nodejs.org/api/net.html#net_socket_write_data_encoding_callback to know when the data is completly flushed to the kernel . Wait for that to happen and after that call the second write. that way you make sure of the ordering. Regarding the problem of logic separartion of "a" and "b" you might want to design/implement that "protocol yourself, it's not a responsiblity of the (low-level) socket API.

提交回复
热议问题