Links2004 / arduinoWebSockets

arduinoWebSockets
GNU Lesser General Public License v2.1
1.9k stars 555 forks source link

[WS-Client][handleHeader] Header error () #615

Closed MatersM closed 3 years ago

MatersM commented 3 years ago

Hi all, I'm at a loss, and I've no clue how to resolve this, I looked at Websocket client handshake is failed #602 to make sure I've got all info you need. See some code and debug info below. I'm using the latest version 2.3.3 (since earlier versions gave the same issue). Also included below the safari developer output - Network to see the request from the client (which does not receive a reply). Hope you folks can help, since I'm stuck after 1 1/2 day trail&error....

Regards,

Martin

** CODE ****

include

include

include

include

include

//#include // cd /Users/mmaters/Library/Arduino15/packages/esp8266/hardware/esp8266/2.7.4/libraries/ESP8266WebServer/src/ changed HTTP_UPLOAD_BUFLEN 2048 => 4096

include

//#include

include

//#include "RemoteDebug.h" //https://github.com/JoaoLopesF/RemoteDebug

include //https://randomnerdtutorials.com/esp8266-nodemcu-date-time-ntp-client-server-arduino/

include

//#include

include

include

ESP8266WebServer server(80); WebSocketsServer webSocket = WebSocketsServer(81); //RemoteDebug Debug;

define HOSTNAME "GAMETABLE"

ifndef STASSID

define STASSID "****"

define STAPSK "*****"

endif

const char ssid = STASSID; const char password = STAPSK;

Timer timer ;

WiFiUDP ntpUDP; NTPClient timeClient(ntpUDP, "pool.ntp.org");

void setup() { Serial.begin(115200); Serial.println("Booting...");

ifdef ESP8266

Serial.println(" EPS8266 ") ;

endif

WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); while (WiFi.waitForConnectResult() != WL_CONNECTED) { Serial.println("Connection Failed! Rebooting..."); delay(5000); ESP.restart(); }

include "OTA.h"

MDNS.addService("telnet", "tcp", 23); //MDNS.addService("websocket", "tcp", 81); //Debug.begin(HOSTNAME); // Initialize the WiFi server //Debug.setResetCmdEnabled(true); // Enable the reset command //Debug.showProfiler(true); // Profiler (Good to measure times, to optimize codes) //Debug.showColors(true); // Colors

initServer() ; Serial.println("HTTP server started"); //debugI("HTTP server started") ;

webSocket.begin(); webSocket.onEvent(webSocketEvent); Serial.println("Websocket Server started on port 81") ; Serial.println("Ready"); Serial.print("IP address: "); Serial.println(WiFi.localIP());

timeClient.begin(); // Set offset time in seconds to adjust for your timezone, for example: // GMT +1 = 3600, GMT +8 = 28800, GMT -1 = -3600, GMT 0 = 0 timeClient.setTimeOffset(3600); Serial.println(" READY ") ; //debugI("Ready...."); } / END SETUP /

** CODE END ****

* Serial output with SSL+TLS_MEM+HTTP_CLIENT+HTTP_SERVER ** Booting... * EPS8266 *** scandone scandone state: 0 -> 2 (b0) state: 2 -> 3 (0) state: 3 -> 5 (10) add 0 aid 6 cnt

connected with PHL-2, channel 9 dhcp client start... ip:192.168.1.78,mask:255.255.255.0,gw:192.168.1.1 HTTP server started [WS-Server] Websocket Version: 2.3.3 [WS-Server] Server Started. Websocket Server started on port 81 Ready IP address: 192.168.1.78 READY pm open,type:2 0 New client request: GET / HTTP/1.1 method: GET url: / search: headerName: Host headerValue: gametable.local headerName: Upgrade-Insecure-Requests headerValue: 1 headerName: Accept headerValue: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8 headerName: User-Agent headerValue: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.2 Safari/605.1.15 headerName: Accept-Language headerValue: nl-nl headerName: Accept-Encoding headerValue: gzip, deflate headerName: Connection headerValue: keep-alive args: args count: 0 args: args count: 0 Request: / Arguments: final list of key/value pairs: HTTP request: ROOT New client request: GET /console1 HTTP/1.1 method: GET url: /console1 search: headerName: Host headerValue: gametable.local headerName: Connection headerValue: keep-alive headerName: Upgrade-Insecure-Requests headerValue: 1 headerName: Accept headerValue: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8 headerName: User-Agent headerValue: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.2 Safari/605.1.15 headerName: Referer headerValue: http://gametable.local/ headerName: Accept-Language headerValue: nl-nl headerName: Accept-Encoding headerValue: gzip, deflate args: args count: 0 args: args count: 0 Request: /console1 Arguments: final list of key/value pairs: HTTP request: CONSOLE [WS-Server][0] new client from 192.168.1.149 [WS-Server][0][handleHeader] RX:  [WS-Client][handleHeader] Header error () [WS-Server][0][handleHeader] RX: [WS-Client][handleHeader] Header error () [WS-Server][0][handleHeader] RX: ⸮ ⸮⸮0⸮/⸮(⸮'⸮⸮⸮ [WS-Client][handleHeader] Header error (⸮ ⸮⸮0⸮/⸮(⸮'⸮⸮⸮) [WS-Server][0][handleHeader] RX:  [WS-Client][handleHeader] Header error () [WS-Server][0][handleHeader] RX: [WS-Client][handleHeader] Header error ()


Safari developper - Network: Overzicht URL: wss://gametable.local:81/ Status: — Bron: —

Request Connection: Upgrade Host: gametable.local:81 Origin: http://gametable.local Pragma: no-cache Cache-Control: no-cache Sec-WebSocket-Key: ImImVeNN8vKLiZlAXeqwQA== Sec-WebSocket-Version: 13 Sec-WebSocket-Extensions: x-webkit-deflate-frame User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.2 Safari/605.1.15

Reply

MatersM commented 3 years ago

Never mind: I did send "wss" instead of "ws"... but stil strange I got this weird message.

Links2004 commented 3 years ago

the browser send the data with SSL/TLS encryption, since the code expect plain text it tried its best to work with it. but since the encryption basically are random bytes, if its not decrypted, you get garbage in the log output that normally prints the plain text protocol.

MatersM commented 3 years ago

Yep, understood it now. Works like a charm without encryption. Thanks for the reply!