Discussion:
[nodejs] Reconnecting to tcp socket server after closing does not work on LAN using Nodejs
Nick Tsutsunava
2017-11-01 13:19:29 UTC
Permalink
I'm experiencing bizarre behaviour which I can't seem to debug. I have a
Electron (NodeJS) application which connects to a remote TCP socket server
(also written in NodeJS) on startup. This works fine.

However, once I disconnect and try to reconnect it hangs on the connect
method.

this.socket = net.connect(this.port, this.host, () => {
this.connected = true
console.log('Connected!')})

The strange thing is, that I do not get this behaviour when the server runs
on 'localhost', this only happens when I run it on a computer on the local
network. The remote server doesn't have a firewall (Ubuntu 16.04).

Now, when I restart the Electron application it connects fine again.

Is there some sort of protocol I am missing when destroying a connection
which is different for localhost as opposed to local networks?

I close the connection from the client like so

close() {
this.connected = false
try {
this.socket.end()
this.socket.destroy()
console.log('Destroying socket connection')
} catch (e) {
console.log(e.message)
}}

Another test that I did was running ncat -l 30000 instead of my NodeJS
server to find out if it was the client or the server causing the trouble.

Turns out it's the client. I can connect to ncat. I can then close the
connection causing ncat to exit. If I restart ncat -l 30000 and try to
connect to it from the client, it doesn't connect.

Repeating this experiment on the same computer as the client (localhost) I
do not experience this behaviour.
--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/c75af3f3-1f4f-4ad8-bbe3-8fc3622f3def%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Anders Thorsby
2018-04-29 13:50:46 UTC
Permalink
Hi Nick,

I just found your post, as I'm experiencing the same problem. Client works
as expected in NodeJS but in Electron it will not reconnect.
Do you have any new information?

best regards
Anders Thorsby
Post by Nick Tsutsunava
I'm experiencing bizarre behaviour which I can't seem to debug. I have a
Electron (NodeJS) application which connects to a remote TCP socket server
(also written in NodeJS) on startup. This works fine.
However, once I disconnect and try to reconnect it hangs on the connect
method.
this.socket = net.connect(this.port, this.host, () => {
this.connected = true
console.log('Connected!')})
The strange thing is, that I do not get this behaviour when the server
runs on 'localhost', this only happens when I run it on a computer on the
local network. The remote server doesn't have a firewall (Ubuntu 16.04).
Now, when I restart the Electron application it connects fine again.
Is there some sort of protocol I am missing when destroying a connection
which is different for localhost as opposed to local networks?
I close the connection from the client like so
close() {
this.connected = false
try {
this.socket.end()
this.socket.destroy()
console.log('Destroying socket connection')
} catch (e) {
console.log(e.message)
}}
Another test that I did was running ncat -l 30000 instead of my NodeJS
server to find out if it was the client or the server causing the trouble.
Turns out it's the client. I can connect to ncat. I can then close the
connection causing ncat to exit. If I restart ncat -l 30000 and try to
connect to it from the client, it doesn't connect.
Repeating this experiment on the same computer as the client (localhost)
I do not experience this behaviour.
--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/e3fde13b-172b-4cb7-af7d-647edb441484%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
John Shaver
2018-04-30 13:18:03 UTC
Permalink
Hey Anders,
Client works as expected in NodeJS but in Electron it will not reconnect.
What version of node is being used in your electron app?

John Shaver
--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/CAMbK04yj6vUqvG7M%2BHCSh06JY2jJA1SWLxT7NL4de7dew9pM9w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
k***@abvtechnology.com
2018-06-07 15:05:05 UTC
Permalink
I am experiencing this same issue.

The versions I am using are:

nodejs: v8.11.1
electron: 2.0.2
--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/f6946b00-a0ba-49f2-a722-319255c7eb26%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...