+ 3

Should someone explain to me Net module in nodejs and how it works?

I am trying to make a chatting web app, not for production,just for fun and get familiar with nodejs, and i have succeeded with ws/WebSocket module!, now just wanted to know more about net built in module of Nodejs

19th Dec 2018, 7:42 PM
Nehemie zikama
Nehemie zikama - avatar
2 Antworten
+ 3
In networking we use many protocols that are built on top of one another. There is Ethernet, which transfers data from device to device on the same network (like, your PC to your router via a wire); on top of that is IP, which is concerned with routing packets correctly to any other router on the internet; on top of that is TCP (among others) which is concerned with keeping a steady connection; on top of that is HTTP or websocket which do their own thing. So a HTTP or WS server is just a TCP server where you send data in a specific format. If you really wanted to, you could use the `net` package, which does TCP, to implement a websocket server "by hand" (its actually not hard) The nodejs `net` servers look and work a lot like the ones from the `http` package if you are familiar with them. Since developers are lazy we rarely use raw TCP connections but sometimes HTTP isn't up for the job and you need to come up with your own protocol (multiplayer games come to mind). I hope that answered some questions.
20th Dec 2018, 4:45 AM
Schindlabua
Schindlabua - avatar
22nd Dec 2018, 5:26 AM
Stéphane Perreault
Stéphane Perreault - avatar