Connect websocket server by LAN IP address

php_nub_qq picture php_nub_qq · Jan 28, 2014 · Viewed 27.1k times · Source

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?

Answer

php_nub_qq picture php_nub_qq · Mar 9, 2014

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!