in socket.io, when does the client.id change? - node.js

if the server is connected to a websocket client using socket.io, what are the events that would cause the client.id to change?
the server reset
the client opening a new connection
are there others, such as timeout?

When client connects to the socket.io server, then new id is generated for the connection. And there is no other place where id is generated.
Server reset, client opening new connection, timeout (and reconnection) - all of these trigger creation of new id, because actually client has to create a new connection to the socket.io server.

Related

how to resolve socket-io send connect request infinitely?

I'm new in socket-io. socket-io working fine but keep sending connect request infinitely to server.
Here is my client ts :
private url = environment.socketServer;
constructor() { this.socket = io(this.url) }
The usual reason for a socket.io client to try to connect over and over is if the socket.io version on the server and client are not compatible. The client connects, the server finds the version is incompatible and drops the connection and the client then tries to connect again, over and over.
Other possible issues:
Server infrastructure (such as load balancers, proxies, firewalls, etc...) are not properly configured to allow webSocket connections.
You're trying to connect to a cluster, but it isn't configured for sticky connections that will "bind" a socket.io client to the same server.
You're confused about how a socket.io connection starts. It is normal for the client to start with a couple web connections in a row (polling) until it realizes that both sides support a webSocket and then socket.io switches over to webSocket.

rpyc, how to handle disconnect and reconnect

using w10/64, python 3.6, rpyc
I have a server receiving serial data and want the data to be published to any client asking for a connection.
In the server I add every client into a connection list and when detecting changes in the data publish it to all clients.
Clients send a "startListening" request to the server including ip and port. The server then opens its own connection to the client to update it with the new data.
I have an "on_disconnect" method in my servers commands class and it gets triggered when a client stops.
When the client restarts and sends a "startListening" again I get an EOFError on the server showing the clients ip/port.
How can I properly detect and close the client connection to allow for a reconnect?

socket.io creates new connection on a new tab

I have used socket.io in my node.js application. When I have one my app in a browser, then new socket connection established, but when I open another tab in same browser, it also create new socket connection. why? and How Do I get socket id on my client?

How to check socket.io connection locally?

My app is in browser, which connects to socket.io server, it works fine, but, when client disconnect for a while ( sleep for example ) , the connection will be automatically closed by server, this is the default behavior for socket.io
How can I re-establish the connection at client side without refreshing the page? is there a status that would tell me that connection is currently off at client side? so that I re-connect when necessary?
I can't rely on an event, I think I need to know if connection is on or off in an easy way locally .. well?
socket.io does reconnect automatically. To check if your socket is connected check socket.socket.connected has Boolean value. See socket.socket.connecting if you are trying to connect.
var socket = io.connect(''); //reconnects by default
console.log(socket.socket.connected);
console.log(socket.socket.connecting);

Can you use the same socket to send the request to server from which you previously send in c++

Suppose you connected to a server through socket connection and for onetime you send the request to the server and receive the response then again you try to send the request to the server but send(); returns -1 because server was down after a while server comes up,can you use the same socket to send request to the server ?
No, when you get the error the connection is no longer valid. Once a connection is invalidated, you should just close the socket; you can't reuse it for a new connection. If the server has gone down, it has no memory of the parameters of the original connection (e.g. port numbers); you need to open a new connection so that the client and server will be in sync.

Resources