Omar Ali
Omar Ali

Reputation: 77

What does "socket" mean in Socket.io?

I've just started learning Socket.io and it seems pretty powerful . I just can't figure out what a socket means and the difference between "io" in the client and server side !

Upvotes: 0

Views: 545

Answers (2)

Amadan
Amadan

Reputation: 198418

"socket" here is a representation of the connection between a client and the server. When you talk to the socket, the other end hears you.

There are two io libraries in Socket.IO: the clientside one, which is responsible for talking to the server, and the serverside one, which maintains connections to multiple clients. They are different because they execute on different architectures (node vs browser) and have different roles, and consequently have different API.

Upvotes: 2

Clayton Bez
Clayton Bez

Reputation: 114

Think of a socket as a pipe between two points. Anything you put in on the one side, comes out the other. So, the "Socket" in socket.io refers to the underlying webSocket transport it uses to make and maintain connections, just like an old TCP Socket connection.

the "io" method of both the server and the client libraries is the initiating functions to start using the libraries. At the server io() has a subset of functions that enables you to launch a server and listen for socket connections on specified port, whereas io() in the client library has a different subset of functions to establish a client connection to a socket. They opted to give it the same name, to keep consistency between code.

Ps. 'io' refers to ON/OFF , very popular with framework type node-modules as naming mechanism

Upvotes: 1

Related Questions