http.createserver vs net.createserver in node.js

前端 未结 3 433
不思量自难忘°
不思量自难忘° 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 07:57

    I don't know much of a Node.js, but I know something about networks. HTTP is a protocol that works on 7th (Application) layer of model OSI. TCP is protocol that works on 4th (Transport) layer of model OSI. As you said, yes HTTP works on top of the TCP. The option of creating HTTP server by http.createServer() is there so you don't have to implement it by yourself by using net.createServer(). The protocol TCP might by used by lot of applications, you might create your own, or implement some different protocol than HTTP, for example: FTP, DNS, SMTP, Telnet and much much more.

提交回复
热议问题