I have set up a websockets chat with the purpose of learning. Everything is working but I can't figure this issue out.
When I supply 127.0.0.1
as the address of the connection on the client side then I can access the server from the computer that's hosting it, but when I change the address to the actual LAN address of the hosting computer I can't connect the server even from the host itself. See:
Server = new FancyWebSocket('ws://127.0.0.1:9300');
Appears to work but only the computer that's hosting the server can connect ( for obvious reasons )
Server = new FancyWebSocket('ws://192.168.1.3:9300');
No computers can connect. I confirm 192.168.1.3
is the LAN address of the hosting computer.
What address do I need to put in there so that other computers from my local network can connect?
I'm pretty sure this is due to the configuration of your WebSocket server. It must be listening to localhost (127.0.0.1
) to accept incoming connections in which case it won't answer to those aiming 192.168.1.3
.
Since you didn't mention which server you are using I can not be specific but in general there are two ways to instantiate a listening socket, binding it to a specific IP address or *
to bind whatever addresses system has. You need to configure the later if you intend to answer server connections coming from any computer within your LAN.
I solved the problem. Since it was a combination of two answers I thought the only fair thing to do was add another answer with an explanation.
As @Mehran suggested, I have had the server address set up as 127.0.0.1
instead of the network address. After changing that to 192.186.1.3
I was able to connect from the server itself, but other machines were unable to connect. Then I did the steps from the guide provided in @vtortola's answer to add a new inbound rule into the server's firewall in order to allow that port to be used.
So finally it all works now, thank you very much for helping me. +rep to everyone!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With