You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi I am also facing the issue of socket.io connectivity in some points in local server as well as in live server. Actually when user login successfully then it jumps to main page or homepage, where I have included notification module .For real-time notification I have used socket.io , its work fine in this page, we can get notification and read notification but If I move to other pages and come back at main page after a while then socket.io lost connection but on page refresh it again maintain its connection. I want that socket.io maintain its connection automatically but at present it is not.
My application is deployed live on a dedicated server. let me share with you the socket connection related code of both server side and client side.
This is the server-side code of socket.io: const server = http.createServer(app); // mount socket.io server const io = new Server(server,{ pingInterval: 10000, // 10 seconds - Interval between server pings pingTimeout: 5000, cors:{ origin:[ "http://localhost:3000", "http:localhost", 'https://mywebdomain.net', 'http://15.15.30.64' ], methods:["GET","POST","PUT"], credentials: true, 'force new connection': true, transports: ['websocket'] } }); Client side code to establish socket.io connection: const ENDPOINT ='https://api.mywebdomain.net' const socketOptions = { reconnectionAttempts: Infinity, reconnectionDelay: 1000, reconnectionDelayMax: 10000, forceNew: true, transports: ['websocket'], }; export const socket = io(ENDPOINT, socketOptions);
Note: in my client side I have maintain connection in index.js and import socket in other files where it needed to emit or listen socket.io event.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi I am also facing the issue of socket.io connectivity in some points in local server as well as in live server. Actually when user login successfully then it jumps to main page or homepage, where I have included notification module .For real-time notification I have used socket.io , its work fine in this page, we can get notification and read notification but If I move to other pages and come back at main page after a while then socket.io lost connection but on page refresh it again maintain its connection. I want that socket.io maintain its connection automatically but at present it is not.
My application is deployed live on a dedicated server. let me share with you the socket connection related code of both server side and client side.
This is the server-side code of socket.io:
const server = http.createServer(app); // mount socket.io server const io = new Server(server,{ pingInterval: 10000, // 10 seconds - Interval between server pings pingTimeout: 5000, cors:{ origin:[ "http://localhost:3000", "http:localhost", 'https://mywebdomain.net', 'http://15.15.30.64' ], methods:["GET","POST","PUT"], credentials: true, 'force new connection': true, transports: ['websocket'] } });
Client side code to establish socket.io connection:const ENDPOINT ='https://api.mywebdomain.net' const socketOptions = { reconnectionAttempts: Infinity, reconnectionDelay: 1000, reconnectionDelayMax: 10000, forceNew: true, transports: ['websocket'], }; export const socket = io(ENDPOINT, socketOptions);
Note: in my client side I have maintain connection in index.js and import socket in other files where it needed to emit or listen socket.io event.
Beta Was this translation helpful? Give feedback.
All reactions