http.createserver vs net.createserver in node.js

前端 未结 3 434
不思量自难忘°
不思量自难忘° 2021-02-02 07:29

I am having trouble understanding the difference between net.createserver and http.createserver in node.js.

I have read the documentation for both methods located at th

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-02 08:02

    http.createServer() sets up a server that handles the HTTP protocol, which is indeed transmitted over tcp. net.createServer() creates a server that simply understands when a TCP connection has happened, and data has been transmitted, and so on, but doesn't know anything about whether a valid HTTP request has been received, etc.

    If you are writing a web server, favor http.createServer() over net.createServer() as it will save you a lot of work. If you are writing some other kind of server, do not use http.createServer().

提交回复
热议问题