Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between socket.io and Node's Net module

I have recently come upon Node's net module, I was wondering if using this module would be the equivalent of using the socket.io module. What is the difference between them ? thanks!

like image 696
Miguel Giménez Avatar asked Jul 30 '18 10:07

Miguel Giménez


People also ask

What is the difference between Socket.IO and Socket.IO client?

socket-io. client is the code for the client-side implementation of socket.io. That code may be used either by a browser client or by a server process that is initiating a socket.io connection to some other server (thus playing the client-side role in a socket.io connection).

What is difference between Socket.IO and WebSocket?

Key Differences between WebSocket and socket.io It provides the Connection over TCP, while Socket.io is a library to abstract the WebSocket connections. WebSocket doesn't have fallback options, while Socket.io supports fallback. WebSocket is the technology, while Socket.io is a library for WebSockets.

Which is better Socket.IO or WS?

Socket.IO is way more than just a layer above WebSockets, it has different semantics (marks messages with name), and does failovers to different protocols, as well has heartbeating mechanism. More to that attaches ID's to clients on server side, and more. So it is not just a wrapper, it is full-featured library.

Which is better Socket.IO or pusher?

Pusher is the category leader in delightful APIs for app developers building communication and collaboration features. On the other hand, Socket.IO is detailed as "Realtime application framework (Node. JS server)". Socket.IO enables real-time bidirectional event-based communication.


1 Answers

I have recently come upon Node's net module, I was wondering if using this module would be the equivalent of using the socket.io module.

No, they are not even close to the same thing.

Node's net module is a basic low level TCP and UDP interface. It allows you to make a TCP or UDP connection to some endpoint and to then send or receive data from that endpoint over that connection. These are raw TCP connections. You define the protocol, data format and all conventions used in the communication. All TCP does is deliver your data from one end to the other.

socket.io is somewhat at the other end of the network stack.

socket.io
webSocket
TCP

A webSocket is built on top of TCP. It has it's own unique connection scheme that starts with an http connection with certain custom headers and then requests an "upgrade" to the webSocket protocol. If the server approves the upgrade, then the same TCP socket that the http connection started over is converted to the webSocket protocol. The webSocket protocol has it's own unique encryption and data format.

Socket.io is built on top of the webSocket protocol (meaning it uses the webSocket protocol for it's communication). Socket.io has it's own unique connection scheme (starts with http polling, then switches to a regular webSocket if permissible) and it has an additional data structure built on top of the webSocket data frame that defines a message name and a data packet and a few other housekeeping things.


socket.io and webSocket are both supported from browser Javascript. A plain TCP or UDP connection is not supported from browser Javascript. So, if you were looking to communicate with a browser, you would not be using plain TCP.

like image 135
jfriend00 Avatar answered Oct 24 '22 21:10

jfriend00