0
Socket Disconnect
Hello Dear Community I am using socket IO with express (server) react JS (client) user after time of inactivity seems to be disconnected and need to reload to see the new changes I made many searches but no specific solution helped me Also my socket connection is not upgrading to WebSocket ; it stuck in polling ; can this be related to my problem ? Any suggestion will be appreciated Thank you in advance
1 Answer
0
Hard to say without seeing your code, but here's an example of how to use WebSocket if that helps. If it isn't using or able to use WebSocket, then it'll default to long-polling and that can certainly cause your issue.
Server-side:
const express = require('express');
const app = express();
const http = require('http').Server(app);
const io = require('socket.io')(http);
// ...
io.on('connection', (socket) => {
// Handle socket connection
});
http.listen(3000, () => {
console.log('Server started on port 3000');
});
Client-side:
import io from 'socket.io-client';
const socket = io('http://localhost:3000', {
transports: ['websocket'],
});
// ...
socket.on('connect', () => {
// Handle socket connection
});