Html – Can websocket client connect to the websocket server from different ports other than 80/443

htmlwebsocket

I am a novice on Websocket programming, but my latest project required to deploy a WebSocket Server on Ubuntu Linux Server. I have read some from the internet, and know –

  1. The websocket client will connect to the server by port 80/443, and its protocol identifier is ws/wss accordingly. http://www.websocket.org/aboutwebsocket.html
  2. The Apache/Nginx web server commonly will listen to 80/443 at server-side, so we have to config Apache/Nginx to support ws/wss protocol, better transmit the connection to a websocket server like a proxy do.
  3. There are some websocket server add-on for Apache, also I know Nginx 1.3+ support websocket protocol natively, and it's fine to config it as well working with a websocket server.

Based on what I knew, I think I can deploy Apache/Nginx and a Websocket Server together through 80/443. I am wondering, if we can just use the websocket server indepdently? I think if we can write a websocket client connecting to the server from other ports , then we can do it.

So can we write a websocket client to connect the server from different port ?

Best Answer

Yes. A standalone WebSocket server can usually be run on any port. Browser clients have no problem opening WebSocket connections to servers on non HTTP(S) ports.

The primary reason that the default ports are 80/443 is that they are the most reliable ports for mass usage due to their ability to traverse many corporate firewalls that block all traffic on all other ports.

If this will not be a problem for your audience (or you have HTTP based fallbacks) it is perfectly reasonable (and a lot easier) to use alternate ports for the WebSocket servers. Another option is to use the 80/443 ports but on a separate IP address/hostname.