Socket connects and disconnects multiple times for a same user
See original GitHub issueWhen the socket get created, same client gets connected and disconnected to the server multiple times.
Server Side Log
Client Side Log
Server code
const httpServer = require("http").createServer();
const io = require("socket.io")(httpServer);
io.on("connection", (socket) => {
console.log("Connected",socket.id)
});
httpServer.listen(3030);
Client Code
import React from 'react';
import { io } from "socket.io-client";
class Room extends React.Component{
componentDidMount = () =>{
const socket = io("http://localhost:3030/");
}
render(){
return (
<div className="room">
<div className="container-fluid">
<label className="subHeading">The Notorious mma</label>
</div>
</div>
);
}
}
export default Room;
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Why socket.io returns multiple times for an event
For broadcast use socket.broadcast.emit(). I don't find any socket disconnection listen event code in your client side code.. try adding ...
Read more >Fullstack2021 | p17 | SocketIO connect and disconnect
In this series we will build a Web application with realtime communication using NestJS (Backend):https://nestjs.
Read more >any workaround on multiple socket.io connection after reconnect
At client side will socket.disconnect() removes all the connections? will following code works to remove multiple connection after reconnect?
Read more >Client API - Socket.IO
Both the client and the server must use the same revision in order to understand each other. You can find more information here....
Read more >How to prevent multiple socket connections and events in React
After that, I experimented on it a bit, and found out that those listeners are still there even after the connection is closed,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@ghirihari pls check out this repo, for reference
private-chat-react
try replacing your socket declaration to
const socket = io(URL, { autoConnect: false });
This will basically not force a user to keep on connecting