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
simple ping pong socket.io example failing after a short time (data payload undefined)
Steps to reproduce
I have a very barebones socket.io example (between node.js client and server) I built because my overall socket.io connection kept reconnecting and this is an effort to debug what's going wrong:
socket-server.js
constapp=require('express')();constserver=require('http').Server(app);constio=require('socket.io')(server);server.listen(8080);console.log("listening...")letcounter=0;setInterval(()=>{letdata={beat: counter};console.log("sending ping",data);io.sockets.emit('ping',data);counter++;},1000);io.on("connection",(socket)=>{console.log("connected to client");socket.on("pong",(data)=>{console.log("pong",data.beat);});});
socket-client.js
vario=require('socket.io-client')varsocket=io.connect('http://127.0.0.1:8080/',{reconnect: true});socket.on('connect',function(socket){console.log('connected to server');});socket.on('ping',function(data){socket.emit('pong',data);console.log('ping',data.beat);});
I start the server and then a few moments later start the client (server and client both node.js in two separate command prompts) (Windows).
I would expect this simple example over localhost to not break down. Since the connection over localhost, my network quality wouldn't be causing a breakdown of the connection, so what gives? How can I debug / fix this?
Setup
v12.16.1:
Windows:
runtime:
socket.io@2.3.0 & socket.io-client:
(No browser involved)
Notes
I tried:
reinstalling socket.io
downgrading to 2.2.0
changing the ports to 3000 instead of 8080
restarting my PC
The text was updated successfully, but these errors were encountered:
You want to:
Current behaviour
What is actually happening?
simple ping pong socket.io example failing after a short time (data payload undefined)
Steps to reproduce
I have a very barebones socket.io example (between node.js client and server) I built because my overall socket.io connection kept reconnecting and this is an effort to debug what's going wrong:
socket-server.js
socket-client.js
I start the server and then a few moments later start the client (server and client both node.js in two separate command prompts) (Windows).
Output of socket-server.js:
Output of socket-client.js:
Expected behaviour
I would expect this simple example over localhost to not break down. Since the connection over localhost, my network quality wouldn't be causing a breakdown of the connection, so what gives? How can I debug / fix this?
Setup
(No browser involved)
Notes
I tried:
The text was updated successfully, but these errors were encountered: