Make your first realtime application!

A journey of learning

Recent post


Most loved posts


Recent comment


Other blogs


blog

Author: Naimur Rahman

Wed Nov 30 2022

Share

A javascript library for making a real-time application known as Socket.io. It’s best for making our website real-time like we get our data without refreshing. It’s used by a lot of large companies.

Let’s discuss socket.io configuring in react app

First of all, let’s install our socket.io on the client side. For that run npm, I socket. io-client-side. It will install socket.io. Then we will import io from a socket. io-client, In a variable name socket, call the io function and then give your API link. It will connect to that server and give a used socket which will help us to make requests and send data through it.

Let’s discuss socket.io configuring in node js server

On the server side install express and add all configuring express apps. Then install socket.io. After that solve cross-policy. Now we need to import Sever from socket.io and create io from that Sever with HTTP value. Then io. on(‘connection’) will provide a callback function which will give our socket. Now we can do socket.on method in the socket

io. After that solve cross-policy. Now we need to import Sever from socket.io and create io from that Sever with HTTP value. Then io. on(‘connection’) will provide a callback function which will give our socket. Now we can do socket.on method in the socket. On socket. on function the first value will be a string like a message then a call back function which will give data if anyone Emit data on message. After that, we have sent data back to all connected users with our server.

d

Send data to all users connected

After that, we will add a socket.broadcast.emit(‘receive massage’). It will send our message data to all connected users but will have to add a socket. on(‘receive massage’) and pass callback function where we will add.

TAGS:#socket.io#socket#realtime#react #node#learn socket
Share

14 COMMENTS:

dfdf

mern developer

3:07:09 PM Tue Mar 28 2023

sadfsafasdf

dfdf

mern developer

3:08:51 PM Tue Mar 28 2023

afdasfdssdf

dfdf

mern developer

3:10:37 PM Tue Mar 28 2023

sadsdfdafd

Leave a comment