Skip to content

ESP32 WebSocket Server Not Accepting Connections

DodaTech Updated 2026-06-26 1 min read

In this tutorial, you'll learn about ESP32 WebSocket Server Not Accepting Connections. We cover key concepts, practical examples, and best practices.

The Problem

ESP32 WebSocket server starts but clients cannot connect or handshake fails.

Quick Fix

Wrong

WebSocketServer ws(81);
ws.begin();
Client connects then disconnects immediately. No handshake.
WebSocketServer ws(81);
ws.begin();
void loop() {
  ws.handleClient();
  WebSocketClient client = ws.accept();
  if (client.connected()) {
    String msg = client.readString();
    client.send("Echo: " + msg);
  }
}
Client connected. ESP32 echoes messages back.

Prevention

Call handleClient() in loop(). Accept clients with accept(). Read and respond in main loop. Limit concurrent connections to available memory.

DodaTech engineers apply these same patterns across Doda Browser, DodaZIP, and Durga Antivirus Pro for production IoT reliability.

FAQ

### How many WebSocket clients can ESP32 handle?

ESP32 handles 4-6 concurrent WebSocket connections depending on memory. AsyncWebServer supports more.

What is the max frame size?

Default 4096 bytes. Configure with ws.setFrameSize(size) before begin(). Larger frames use more memory.

How to broadcast to all clients?

Maintain a list of connected clients and iterate to send messages. Remove disconnected ones.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro