2

I have a web app running on HTTP server on port 3000. This app is connected to a websocket server on port 9001. Both WS and HTTP servers are located inside the same VM.

When testing the app locally (inside VM), everything works fine. Both web app and WS server can communicate with each other. Both the app and the server listen for a connection on localhost as follows:

Web app (ReactJS): const sock = new WebSocket('ws://localhost:9001/');

WS Server (Python): ws = WebsocketServer(host='127.0.0.1', port=9001)

When setting this up to allow external connections, the web app and WS server can't communicate anymore. The server still listens for connections on host='127.0.0.1'. The web app frontend code is changed to connect to a machine where VM runs (let's say 123.45.67.890):

Web app (ReactJS): const sock = new WebSocket('ws://123.45.67.890:9001/');

I enabled port forwarding for both ports 3000 and 9001, and disabled firewall on both ports from inside the VM. Both ports are open on the host machine.

I can access the web app from the outside using 123.45.67.890:3000, so I am pretty sure that the connection to the VM is open. However, the web app doesn't communicate with the WS server on port 9001. Any ideas what might be the cause of this?

Just in case OS info is helpful:

VM Host: Microsoft Windows 7 Enterprise (6.1.7601 Service Pack 1 Build 7601)

VM Guest: CentOS Linux release 7.4.1708 (Core)

Max Mikhaylov
  • 171
  • 1
  • 1
  • 6

1 Answers1

4

This was pretty easy to fix and is even written in the docs of the websocket server that I am using.

Just needed to instantiate the WS server as follows ws = WebsocketServer(host='0.0.0.0', port=9001) so that it listens for all incoming connections.

Max Mikhaylov
  • 171
  • 1
  • 1
  • 6