Chat here about code rewrites, mods, etc... with respect to the github project https://github.com/esp8266/Arduino

Moderator: igrr

User avatar
By chrisAdmin
#47220 I'm trying to merge websocket support with the `ESP8266WebServer`, but can't get hold of a WiFi client (variable?) to allow the websocket to handshake.

The WebSocket code uses the WiFlyServer and grabs the client connection like this:
Code: Select allvoid loop() {
  String data;
  WiFlyClient client = server.available();                   // <---- get client connection
 
  if (client.connected() && webSocketServer.handshake(client)) {   // <---- handshake
   
    while (client.connected()) {
      data = webSocketServer.getData();

      if (data.length() > 0) {
        handleClientData(data);
      }

      sendClientData(1);
    }
  }


But `ESP8266WebServer`is event driven, so I need something like the following:

Code: Select allserver.on("/test", HTTP_GET, [](){ webSocketServer.handshake((client) server.available()); }, handleTestPage);


`server.available()` isn't part of the `ESP8266WebServer`library, so how can i get the client out of it?

or better, does anyone know of some websocket code that is compatible with `ESP8266WebServer` ?