innovationM
← 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

Transform Your Ideas with Expert Guidance

icon
15+ Years of Expertise

Delivering high-impact solutions with years of industry experience.

icon
100+ Satisfied Clients

Helping contact industry software experts to achieve their brand goals.

icon
250+ In-House Team Members

A skilled team ready to tackle projects of any scale.

Book a consultation call with our experts today