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='', 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=''. The web app frontend code is changed to connect to a machine where VM runs (let's say

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

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, 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)

1 Answer 1


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='', port=9001) so that it listens for all incoming connections.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.