I trying to close already opened socket at server end but i didn't get any info regarding how to close.
Is there any way to close already opened TCP sockets in server using node
in server client model, due to some issue the connection got closed and unfortunately server don't know that the connection got closed, client initiated new connection then at server end - it will create new connection. so here i want to close already opened (old) connection
how to delete the old socket is my query. i want to delete it using node JS - is it possible ?
Related
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?
Say there are 5 open tabs in a single browser, and I am using Node.js and Socket.io. The client and server exchange packets to maintain (establish) communications.
Will connection with the client be lost if of one tab is closed?
How can I determine if the user closed the browser?
Yes, socket.io establishes a new connection with every tab. You're going to want to look into using session cookies to figure out which user the current socket.io connection is communicating with.
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?
I'm new in node.js
So the question can be quite naive.
I want to use node.js as a proxy between the javascript client and a windows program which has a API working through a defined port.
So browser sends HTTP request to node.js.
Node.js opens connection with the windows program, sends request, get a respons and returns the response to the javascript that called node.js ( AJAX )
Actually it has been realized so and works.
The problem is that windows program wants to work persistent.
So once the connection is opened it should stay alive.
And my node.js script opens connection. And the next call to node.js try to open connection again. And that leads to error.
So the question - what is the right way and middles to reuse the TCP connection in node.js.
So that next call won't open new connection but go on with already opened one.
It is possible, but requires some coding on your side.
If it is not sticky (the same HTTP client does not require to use the same TCP connection):
Open an connection pools of TCP connections to the windows program
Listen to HTTP requests
If a HTTP request arrives find an unused TCP connection (if none is available, make a new one or wait)
Query the windows program, return the results to who ever called the HTTP request
Mark the TCP connection as free
If it is sticky (always use the same TCP connection for the same HTTP client):
If a HTTP clients connect and he hasn't one, give him session.
If not available for the session: create a TCP connection
Make the request, return the result
Store the TCP "connection" somewhere where you could reach it when the next request comes in and you could identify it by the HTTP clients session (Maybe make a timeout for clearing up)
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);