Skip to the content.

Message Queues

✔back to main

web sockets are bidirectional means it handles both client-side and server-side. Whereas HTTP relies on a client request to receive a response from the server for every exchange, WebSockets allow for full-duplex bidirectional communication. This enables the server to send real-time updates asynchronously, without requiring the client to submit a request each time.

no, Socket.IO is always dependent on a http server

the event gets passed to the server through websockets. Its a tcp connection from the browser to the server. The connection is full duplex meaning the server can send real time data to the client and vise versa.

when the server listen to the connection event. When that event is invoked, socket.io pass a socket object to our function. We then listen to all of our sockets for a chat. As defined on the client side, take the data emited from the chat and emit it back to all of our sockets.

it stored in queue until the client get opportunity to listen the event.

Terms

a socket is an endpoint of a communication between two programs running on a network. Sockets are used to create a connection between a client program and a server program

The WebSocket object provides the API for creating and managing a WebSocket connection to a server, as well as for sending and receiving data on the connection.

The Clients interface provides access to Client objects.

framework can be used to develop web servers using the ‘http’ module.

The OSI model is an architectural model that represents networking communications.

TCP (Transmission Control Protocol) is a protocol for sending information between computers.

TCP (Transmission Control Protocol) is a protocol for sending information between computers.

UDP (User Datagram Protocol) is a long standing protocol used together with IP for sending data when transmission speed and efficiency matter more than security and reliability.

a packet is a small segment of a larger message. Data sent over computer networks*, such as the Internet, is divided into - packets.

Socket.io Chat example

Sockets have traditionally been the solution around which most real-time chat systems are architected, providing a bi-directional communication channel between a client and a server The server can push messages to clients

Whenever you write a chat message, the idea is that the server will get it and push it to all other connected clients Setup steps here

Room is an arbitrary channel that sockets can join and leave, it can be used to broadcast events to a subset of clients Rooms are a server-only concept (client does not have access to the list of rooms it has joined) Can join to subscribe the socket to a given channel socket.join()

Each socket in Socket.io is identified by a random unique identifier (Socket#id), each socket automatically joins a room identified by its own id

Upon disconnection, sockets leave all the channels they were part of automatically.

references

chat example on socket.io

rooms

nameSpaces

cheatSheet