Websocket don´t work
Mike0675 opened this issue · comments
Describe the bug
I can´t use WebSockets with Async_WebServer_Teensy41.
I adopted a Sketch from ESP32 where it works well.
With Teensy 4.1 the Connection establishes but send no Data to the Client (HRESULT: 0x80072F78).
Im using Windows10, "Websocket Debug Tools", Wireshark
Arduino IDE version 1.8.19
Teensyduino Core v1.58 beta3
QNEthernet library version v0.17.0
Steps to Reproduce
I used Async_AdvancedWebServer Example
and added:
AsyncWebSocket ws("/ws");
void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *WS_Client, AwsEventType type, void *arg, uint8_t *data, size_t len) {
if (type == WS_EVT_CONNECT) {
Serial.println("Websocket client connection received");
WS_Client->text("Hello from ESP32 Server");
} else if (type == WS_EVT_DISCONNECT) {
Serial.println("Client disconnected");
}
}`
In SETUP:
ws.onEvent(onWsEvent);
server.addHandler(&ws);`
In LOOP:
if (millis() > timer + 5000) {
ws.textAll(String(millis() / 1000));
timer = millis();
}
Expected behavior
The Server should send back "Hello from Teensy 4.1 Server".
Every 5s the Server should send millis() / 1000.
Actual behavior
With "Websocket Debug Tools" I get (HRESULT: 0x80072F78)
Using Wireshark it seems the OPCODE for Websocket Connection is Wrong.
Please post the MRE, as well as all the tests procedures / results so far, to save anybody time to duplicate the issue.
Also try to adapt the example from sibling library Async_WebSocketsServer, written for RP2040W AsyncWebServer_RP2040W
Hi @Mike0675
I just adapted the Async_WebSocketsServer code and posted in this library as Async_WebSocketsServer for Teensy4_1
The WebSockets Server is working correctly, meaning the WS protocol is handled correctly in this library
The terminal debug is
Async_WebSocketsServer on TEENSY 4.1
Starting Async_WebSocketsServer on TEENSY 4.1
with Teensy4.1 QNEthernet
AsyncWebServer_Teensy41 v1.6.1
Initialize Ethernet using DHCP => Connected! IP address:192.168.2.119
ws[Server: /ws][ClientID: 1] WSClient connected
ws[Server: /ws][ClientID: 1] text-message[len: 13]: Hello, Server
ws[Server: /ws][ClientID: 1] WSClient disconnected
ws[Server: /ws][ClientID: 2] WSClient connected
ws[Server: /ws][ClientID: 2] text-message[len: 13]: Hello, Server
ws[Server: /ws][ClientID: 2] WSClient disconnected
ws[Server: /ws][ClientID: 3] WSClient connected
ws[Server: /ws][ClientID: 3] text-message[len: 13]: Hello, Server
The WebSockets Client code using python used to test
Just modify to match the IP of the server. In this case 192.168.2.119