Binding to a Different Port or IP Address
By default WebSocket requests will be served on the same IP and port as the main HTTP server. For example, if your application is running on port 8077 the same port will be used to serve WebSocket requests. If your application URL looks like http://myserver.com:8077 then the WebSocket connection URL will be ws://myserver.com:8077. The same HTTP server is used to serve both HTTP and WebSocket requests. This scenario is valid for Standalone Server and Service Application. In these applications there is no need to bind to a different port or IP address, as the main HTTP server can serve both HTTP and WebSocket requests.
However, if your application is deployed as an ISAPI or Apache module there will be no internal HTTP server in the module. The external web server (IIS, Apache, etc.) runs its own internal HTTP server. Each web server uses its own specialized method to interface with WebSockets (some such as IIS use a specialized API, while others use rewrite rules and proxying techniques). See IIS & Apache Deployment for details: https://unigui.com/doc/online_help/iis--apache-deployment.htm.
In general, when your deployment method is not Standalone Server or Service (Windows or Linux) you should choose a different port and/or IP address to serve WebSocket requests. When you choose a different port or IP uniGUI will run a separate HTTP server listening on this new port. If you choose an IP address as well this server will bind itself to that IP address. All WebSocket requests will be directed to this dedicated HTTP server.
Configuring a different port
To configure a different port for WebSockets make the following changes in your application (or in the HyperServer configuration file if your application runs in a HyperServer cluster):
Set AuxPort on WebSocketServer
In your application's ServerModule find the WebSocketServer class property. Under this class there is a property named AuxPort. The default value for AuxPort is 0, which means no additional port will be used for WebSockets. Setting a non-zero value forces uniGUI to create a new HTTP server which will listen to incoming WebSocket requests on AuxPort.
Example:
If your web application runs on port 8077 and
AuxPortis set to 8088:Regular HTTP requests are served on port 8077 (http://myserver.com:8077).
WebSocket requests are served on port 8088 (ws://myserver.com:8088).
For ISAPI/Apache modules, regular HTTP calls are handled by IIS/Apache while the internal HTTP server (listening on 8088) serves WebSocket requests.
Firewall and proxy considerations
When you configure an auxiliary port, ensure that:
The auxiliary port is accessible through your server firewall and any other network firewalls.
Clients that access your web application are also able to access this additional port (it must not be blocked on client-side networks).
If opening this extra port is not possible, you can use an internal proxy to redirect external WebSocket calls (e.g. ws://globalurl) to a local auxiliary port (e.g. ws://localurl:aux_port). This typically requires a URL rewrite rule or proxy configuration on your web server that redirects external ws:// requests to the internal WebSocket server running on a different port.
To support this proxying approach you must set the GlobalPort parameter or set a value for the GlobalBinding property including the correct global port number so the global URL/port exposed to clients is correct.
Configuring a different IP address
If your environment restricts opening ports (for example, only ports 80 and 443 are allowed), you can dedicate a secondary IP on your server for WebSocket requests instead of using a different port. In this scenario you do not need to change the port number because the secondary IP will listen on the same port as your main HTTP server.
To configure a different IP:
Ensure a secondary global IP is available on your server.
Set the
Bindingproperty of theWebSocketServerclass to the secondary IP address which the WebSockets HTTP server should bind to.If the internal binding IP differs from the public/global IP (for example when a router redirects a global IP to an internal server), also set
GlobalBindingto the appropriate global IP or URL.
This ensures that WebSocket connections are served by the dedicated IP address while keeping the same port as the main HTTP server.
References:
Standalone Server: https://unigui.com/doc/online_help/standalone_server.htm
Service (Windows/Linux): https://unigui.com/doc/online_help/windows_service.htm
IIS & Apache Deployment: https://unigui.com/doc/online_help/iis--apache-deployment.htm