• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Websocket service on port 81

Q&A Forum › Category: ESP32 › Websocket service on port 81
0 Vote Up Vote Down
Dr ValleeCussac asked 1 month ago

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 ?

Question Tags: WebsocketService
1 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 1 month ago

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

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.