ESPAsyncWebServer icon indicating copy to clipboard operation
ESPAsyncWebServer copied to clipboard

How to connect to WebSocket as client in ESP32?

Open augustoeliezer opened this issue 5 years ago • 7 comments

In AsyncWebSocketClient have a client connected to AsyncWebSocket. But how to connect as client in ESP32? Server.ino

void setup() {
//...
  AsyncWebSocket ws("/ws");
  ws.onEvent(onEvent);
  server.addHandler(&ws);
  //...
}

TODO

Client.ino

void setup() {
  //...
  AsyncWebSocketClientRequest wsc("ws://192.168.4.1:80/ws");
  
  if (wsc.connect()) {
  
    wsc.onData([](String data) {
  
    });
  }
  //...
}

augustoeliezer avatar Mar 16 '21 17:03 augustoeliezer

[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jun 02 '21 16:06 stale[bot]

Any suggestion?

augustoeliezer avatar Jun 03 '21 19:06 augustoeliezer

[STALE_CLR] This issue has been removed from the stale queue. Please ensure activity to keep it openin the future.

stale[bot] avatar Jun 03 '21 19:06 stale[bot]

Hi @augustoeliezer, it doesn't work for me either. I had to use another WS client, see my code.

jendakol avatar Jun 03 '21 19:06 jendakol

I know this is a rather old issue, but for future reference maybe try using ArduinoWebsockets on the client side. With a static ip on the server side you can access your websocket by "ws://your_static_ip:port/ws". If you stick with the example code snippets your port number is likely 80.

Squanchy42 avatar Jul 14 '21 06:07 Squanchy42

[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Sep 19 '21 19:09 stale[bot]

[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions.

stale[bot] avatar Oct 12 '21 21:10 stale[bot]