I'm running a simple websocket server in nodejs
const WebSocket = require('ws');
const wss = new WebSocket.Server({ host: '0.0.0.0', port: 13000 });
wss.on('connection', function connection(ws) {
console.log("new connection");
ws.on('message', function incoming(message) {
console.log('received: %s', message);
});
ws.on('error', function(e) {
console.log('error', e);
});
ws.on('close', function(e) {
console.log('close', e);
});
ws.send('something');
});
I can connect to the server using:
s=new WebSocket('ws://localhost:13000')
and everything is fine. But if I try to connect from another computer:
s=new WebSocket('ws://serveripaddress:13000')
The server shows
new connection
close 1006
So I know that the client connects, but it then immediately disconnects. I am totally lost here, don't know how to diagnose my problem. Any ideas?
UPDATE
These scenarios work:
- two ec2 instances: works
- two linux VMs communicating over a host-only network: works
And these fail:
- windows host machine and VM (host only network): fail
- an ec2 instance and one of my VM's: fail
Here's the weird part, if I make a simple socket server using 'net', ALL scenarios above work! So it seems like its still a networking issue (since websockets work in some scenarios) but it is a networking issue specific to websockets (because socket server works where websocket doesnt)!
I dont have access to the firewall that my windows host machine is on so if that's the issue then I'm stuck. But I will try this all on a different host machine where I have access to the firewall.
But if it was the firewall, I would except it to work between the windows host and the VM because they are on their own virtual network...