By declaring AsyncWebServer server(80) and AsyncWebSocket ws(“/ws”), on which port is the WenSocket service established?
For our application, we need to converse with a client application that uses the standard ports: Web Service 80 and Websocket Service 81.
How do you set the Websocket service to 81 with AsyncTCP.h et ESPAsyncWebServer.h> libraries?
N.B.: For a previous application we developed, we used the libraries: WebServer.h and WebSocketsServer.h
and the instructions: WebServer server(80) and WebSocketsServer webSocket = WebSocketsServer(81)
What’s the equivalence ?
Hi.
I think in this case, both are on port 80, but the websockets run on the /ws endpoint.
I don’t think the library allows you to set one port for each. So, you’ll have two create two instances of the AsyncWebServer object, one in each port. Then, put the websocket listening on the AsyncWebServer object on port 81. I’m not sure if this will work. but you can try it.
//HTTP server on port 80 AsyncWebServer httpServer(80); // WebSocket server on port 81 AsyncWebServer wsServer(81); // here we're creating another instance of the AsyncWebServer on a different port AsyncWebSocket ws("/ws");
Then, in the setup(), add something like this:
// Configure WebSocket server on port 81 ws.onEvent(onWebSocketEvent); wsServer.addHandler(&ws); wsServer.begin();
The AsyncWebSocket object (ws) is attached to wsServer using wsServer.addHandler(&ws).
I hope this helps.
Let me know if you succeed.
Regards,
Sara