Tech Tip: Programmatically check if web server started before creating WebSocket server
PRODUCT: 4D | VERSION: 19 | PLATFORM: Mac & Win
Published On: July 20, 2023
In v20, WebSocketServer is a new 4D class that enables creation of a WebSocket server for WebSocket connections. WebSocket servers are run via the 4D Web Server. Consequently, the web server must be started before a WebSocket server can be created. When initiating a WebSocket server, it is recommended to programmatically check if the web server has started beforehand. To do this, use the WEB server command like below:
$web_server:=WEB Server(Web server host database) If (Not($web_server.isRunning)) $web_server.start() End if |
The above code instantiates the host database’s web server object, and then uses its “isRunning” property to verify if the web server is running. Then, it uses the start( ) method to programmatically start the web server if it’s not already running.