You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
ESP32 is configured as server that accepts multiple clients. When connecting from firefox browser using server.poll(), two clients are registered (in most cases).
When this happens, no more code is executed. (It appears to be trapped in handshake part of server.accept() ).
To Reproduce
Using below code, connect to the esp32 board from firefox browser.
Library version 0.4.14
Board: ESP32-CAM
Firefox 71.0 (64-bit)
Expected behavior
Only 1 client is added to the list for each new connection (which is what happens in chrome).
Code
#include<WiFi.h>
#include<ArduinoWebsockets.h>usingnamespacewebsockets;constchar *ssid = "xxxx";
constchar *password = "xxxx";
constint maxClients = 4; // Accept up to 4 connections
WebsocketsServer server;
WebsocketsClient clients[maxClients];
int nClients = 0;
voidsetup()
{
Serial.begin(115200);
while (!Serial)
;
// WIFI SETUP
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("WiFi connected, IP: ");
Serial.println(WiFi.localIP());
// WEBSOCKET: Open websocket on port 80
server.listen(80);
Serial.print("Is server live? ");
Serial.println(server.available());
}
voidloop()
{
if (server.available())
{
// if there is a client that wants to connectif (server.poll() && nClients < maxClients)
{
//accept the connection and register callback
Serial.print("Accepting a new client! Number of clients accepted: ");
Serial.println(nClients + 1);
WebsocketsClient client = server.accept();
client.onMessage(onMessage);
// store it for later use
clients[nClients] = client;
nClients++;
delay(10);
}
// check for updates in all clientspollAllClients();
delay(10);
}
}
// this method goes thrugh every client and polls for new messages and eventsvoidpollAllClients()
{
for (int i = 0; i < nClients; i++)
{
clients[i].poll();
}
}
// this callback is common for all clients, the client that sent that// message is the one that gets the echo responsevoidonMessage(WebsocketsClient &client, WebsocketsMessage message)
{
Serial.print("Got Message: ");
Serial.print(message.data());
Serial.println(", Sending Echo.");
client.send("Echo: " + message.data());
}
So, I was able to reproduce. The problem as far as I understand it has nothing to do with the library itself, it seems like esp32's WiFiServer impl claims that there is a client when there is not.
I will keep looking into it, meanwhile, you can check if the client that you got is connected by calling client.available. If it returns false, just skip that client.
Was there any solution to this? I am working with this otherwise great implementation, but looping even for 1 client does not seem to work. Always gets disconnected after the initial message was properly received (without me calling cloe() on the server)...
Describe the bug
ESP32 is configured as server that accepts multiple clients. When connecting from firefox browser using server.poll(), two clients are registered (in most cases).
When this happens, no more code is executed. (It appears to be trapped in handshake part of server.accept() ).
To Reproduce
Using below code, connect to the esp32 board from firefox browser.
Expected behavior
Only 1 client is added to the list for each new connection (which is what happens in chrome).
Code
The text was updated successfully, but these errors were encountered: