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.
Client works as expected in NodeJS but in Electron it will not reconnect.