← Back to Blogs

Client server model

SOCKET IO

InnovationM Admin 27 Jul 2023 1 min read
SOCKET IO

Socket.IO is a library that enables bidirectional and event-based communication between clients and servers.

Installation:

Open Cmd and run the command given below:

npm install socket.io-client

 

Import:

import * as io from 'socket.io-client';

 

Connection:

  1. From same domain 

 

  1. From different domain

 

In case of different domains, please make sure to enable Cross-Origin Resource Sharing (CORS) on the server.

 

Events:

1. Adding Event Listener to socket

socket.on("connect", () => {

 console.log(socket.id); // x8WIv7-mJelg7on_ALbx

});

 

  • Removing Socket Listeners : 
socket.off("connect", () => {

 console.log(socket.id); // x8WIv7-mJelg7on_ALbx

});
About the Author
InnovationM Admin

Contributor at InnovationM.

LinkedIn

We don't
predict
the future.
We build what
comes next.

Share your goals, challenges, or ideas, we'll help you turn them into scalable digital solutions.