From 0d9aa043f004352711509a5e684edba195b17b57 Mon Sep 17 00:00:00 2001 From: Markus Date: Sat, 22 Oct 2016 20:36:36 +0200 Subject: [PATCH 01/14] fix WebSocketClientSocketIO example --- examples/WebSocketClientSocketIO/WebSocketClientSocketIO.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/WebSocketClientSocketIO/WebSocketClientSocketIO.ino b/examples/WebSocketClientSocketIO/WebSocketClientSocketIO.ino index 6d08b02..9f54361 100644 --- a/examples/WebSocketClientSocketIO/WebSocketClientSocketIO.ino +++ b/examples/WebSocketClientSocketIO/WebSocketClientSocketIO.ino @@ -86,7 +86,7 @@ void setup() { delay(100); } - webSocket.begin("192.168.0.123", 81); + webSocket.beginSocketIO("192.168.0.123", 81); //webSocket.setAuthorization("user", "Password"); // HTTP Basic Authorization webSocket.onEvent(webSocketEvent); From d2719573d44a67872bbf9bb2886f42fcd67ebfba Mon Sep 17 00:00:00 2001 From: Markus Sattler Date: Sat, 22 Oct 2016 19:47:44 +0200 Subject: [PATCH 02/14] add function to send WS ping sendPing(); #130 --- src/WebSocketsClient.cpp | 18 ++++++++++++++ src/WebSocketsClient.h | 3 +++ src/WebSocketsServer.cpp | 51 ++++++++++++++++++++++++++++++++++++++++ src/WebSocketsServer.h | 6 +++++ 4 files changed, 78 insertions(+) diff --git a/src/WebSocketsClient.cpp b/src/WebSocketsClient.cpp index 3b93a14..9b4aad0 100644 --- a/src/WebSocketsClient.cpp +++ b/src/WebSocketsClient.cpp @@ -207,6 +207,24 @@ bool WebSocketsClient::sendBIN(const uint8_t * payload, size_t length) { return sendBIN((uint8_t *) payload, length); } +/** + * sends a WS ping to Server + * @param payload uint8_t * + * @param length size_t + * @return true if ping is send out + */ +bool WebSocketsClient::sendPing(uint8_t * payload, size_t length) { + if(clientIsConnected(&_client)) { + return sendFrame(&_client, WSop_ping, payload, length); + } + return false; +} + +bool WebSocketsClient::sendPing(String & payload) { + return sendPing((uint8_t *) payload.c_str(), payload.length()); +} + + /** * disconnect one client * @param num uint8_t client id diff --git a/src/WebSocketsClient.h b/src/WebSocketsClient.h index 2a8bc3e..bae1777 100644 --- a/src/WebSocketsClient.h +++ b/src/WebSocketsClient.h @@ -69,6 +69,9 @@ class WebSocketsClient: private WebSockets { bool sendBIN(uint8_t * payload, size_t length, bool headerToPayload = false); bool sendBIN(const uint8_t * payload, size_t length); + bool sendPing(uint8_t * payload = NULL, size_t length = 0); + bool sendPing(String & payload); + void disconnect(void); void setAuthorization(const char * user, const char * password); diff --git a/src/WebSocketsServer.cpp b/src/WebSocketsServer.cpp index 53641d2..c2262f6 100644 --- a/src/WebSocketsServer.cpp +++ b/src/WebSocketsServer.cpp @@ -283,6 +283,57 @@ bool WebSocketsServer::broadcastBIN(const uint8_t * payload, size_t length) { return broadcastBIN((uint8_t *) payload, length); } + +/** + * sends a WS ping to Client + * @param num uint8_t client id + * @param payload uint8_t * + * @param length size_t + * @return true if ping is send out + */ +bool WebSocketsServer::sendPing(uint8_t num, uint8_t * payload, size_t length) { + if(num >= WEBSOCKETS_SERVER_CLIENT_MAX) { + return false; + } + WSclient_t * client = &_clients[num]; + if(clientIsConnected(client)) { + return sendFrame(client, WSop_ping, payload, length); + } + return false; +} + +bool WebSocketsServer::sendPing(uint8_t num, String & payload) { + return sendPing(num, (uint8_t *) payload.c_str(), payload.length()); +} + +/** + * sends a WS ping to all Client + * @param payload uint8_t * + * @param length size_t + * @return true if ping is send out + */ +bool WebSocketsServer::broadcastPing(uint8_t * payload, size_t length) { + WSclient_t * client; + bool ret = true; + for(uint8_t i = 0; i < WEBSOCKETS_SERVER_CLIENT_MAX; i++) { + client = &_clients[i]; + if(clientIsConnected(client)) { + if(!sendFrame(client, WSop_ping, payload, length)) { + ret = false; + } + } +#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) + delay(0); +#endif + } + return ret; +} + +bool WebSocketsServer::broadcastPing(String & payload) { + return broadcastPing((uint8_t *) payload.c_str(), payload.length()); +} + + /** * disconnect all clients */ diff --git a/src/WebSocketsServer.h b/src/WebSocketsServer.h index 7a93c0e..f6acee5 100644 --- a/src/WebSocketsServer.h +++ b/src/WebSocketsServer.h @@ -81,6 +81,12 @@ public: bool broadcastBIN(uint8_t * payload, size_t length, bool headerToPayload = false); bool broadcastBIN(const uint8_t * payload, size_t length); + bool sendPing(uint8_t num, uint8_t * payload = NULL, size_t length = 0); + bool sendPing(uint8_t num, String & payload); + + bool broadcastPing(uint8_t * payload = NULL, size_t length = 0); + bool broadcastPing(String & payload); + void disconnect(void); void disconnect(uint8_t num); From 75133dfa6d6c0f4d52fbb61b37b371d4ecb4512c Mon Sep 17 00:00:00 2001 From: Markus Sattler Date: Sat, 22 Oct 2016 19:48:16 +0200 Subject: [PATCH 03/14] version bumb --- library.json | 2 +- library.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library.json b/library.json index c8a3b09..46de566 100644 --- a/library.json +++ b/library.json @@ -13,7 +13,7 @@ "type": "git", "url": "https://github.com/Links2004/arduinoWebSockets.git" }, - "version": "2.0.5", + "version": "2.0.6", "license": "LGPL-2.1", "export": { "exclude": [ diff --git a/library.properties b/library.properties index 0c5c9bd..0725e3f 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=WebSockets -version=2.0.5 +version=2.0.6 author=Markus Sattler maintainer=Markus Sattler sentence=WebSockets for Arduino (Server + Client) From 689e3ef92116eb8e70605f067d6f60aa3624c7c1 Mon Sep 17 00:00:00 2001 From: Ugo Riboni Date: Tue, 8 Nov 2016 01:48:01 +0100 Subject: [PATCH 04/14] Change inheritance of WebSocketServer to allow classes inheriting from it to call sendFrame with custom arguments. --- src/WebSocketsServer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WebSocketsServer.h b/src/WebSocketsServer.h index f6acee5..654bd41 100644 --- a/src/WebSocketsServer.h +++ b/src/WebSocketsServer.h @@ -33,7 +33,7 @@ -class WebSocketsServer: private WebSockets { +class WebSocketsServer: public WebSockets { public: #ifdef __AVR__ From a097f0defdf5b30fef54ee0e128ea319dbf88bb6 Mon Sep 17 00:00:00 2001 From: Ugo Riboni Date: Tue, 8 Nov 2016 22:52:00 +0100 Subject: [PATCH 05/14] protected inheritance is enough --- src/WebSocketsServer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WebSocketsServer.h b/src/WebSocketsServer.h index 654bd41..b50effa 100644 --- a/src/WebSocketsServer.h +++ b/src/WebSocketsServer.h @@ -33,7 +33,7 @@ -class WebSocketsServer: public WebSockets { +class WebSocketsServer: protected WebSockets { public: #ifdef __AVR__ From 5cd68c5304f142c730e0d565411c202a393ae244 Mon Sep 17 00:00:00 2001 From: quantumlicht Date: Wed, 16 Nov 2016 18:31:39 -0500 Subject: [PATCH 06/14] - Remove duplicate handshake headers - Add debug log for displaying handshake headers Host, Origin, and User-Agent were duplicated in the case the client was not socketIO or if it was and has a sessionId --- src/WebSocketsClient.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/WebSocketsClient.cpp b/src/WebSocketsClient.cpp index 9b4aad0..3e2e49d 100644 --- a/src/WebSocketsClient.cpp +++ b/src/WebSocketsClient.cpp @@ -426,11 +426,8 @@ void WebSocketsClient::sendHeader(WSclient_t * client) { transport = "&transport=websocket&sid=" + client->cSessionId; } handshake = "GET " + client->cUrl + transport + " HTTP/1.1\r\n" - "Host: " + _host + ":" + _port + "\r\n" "Connection: Upgrade\r\n" "Upgrade: websocket\r\n" - "Origin: file://\r\n" - "User-Agent: arduino-WebSocket-Client\r\n" "Sec-WebSocket-Version: 13\r\n" "Sec-WebSocket-Key: " + client->cKey + "\r\n"; @@ -460,7 +457,7 @@ void WebSocketsClient::sendHeader(WSclient_t * client) { } handshake += "\r\n"; - + DEBUG_WEBSOCKETS("[WS-Client][sendHeader] handshake %s", handshake.c_str()); client->tcp->write(handshake.c_str(), handshake.length()); #if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC) From 45bb7dbe238408ff55cd32228f174515632297dd Mon Sep 17 00:00:00 2001 From: Markus Date: Wed, 23 Nov 2016 17:39:48 +0100 Subject: [PATCH 07/14] Update WebSocketsClient.cpp fix #140 Socket.io client doesn't reconnect to server --- src/WebSocketsClient.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/WebSocketsClient.cpp b/src/WebSocketsClient.cpp index 3e2e49d..8866327 100644 --- a/src/WebSocketsClient.cpp +++ b/src/WebSocketsClient.cpp @@ -331,6 +331,7 @@ void WebSocketsClient::clientDisconnect(WSclient_t * client) { client->cVersion = 0; client->cIsUpgrade = false; client->cIsWebsocket = false; + client->SessionId = ""; client->status = WSC_NOT_CONNECTED; From ab3b5bae4656bac77bc645b18260eac39e27220b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Toledo?= Date: Thu, 24 Nov 2016 02:25:01 -0200 Subject: [PATCH 08/14] Update WebSocketsClient.cpp fix typo that was breaking the build --- src/WebSocketsClient.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WebSocketsClient.cpp b/src/WebSocketsClient.cpp index 8866327..0cb1f38 100644 --- a/src/WebSocketsClient.cpp +++ b/src/WebSocketsClient.cpp @@ -331,7 +331,7 @@ void WebSocketsClient::clientDisconnect(WSclient_t * client) { client->cVersion = 0; client->cIsUpgrade = false; client->cIsWebsocket = false; - client->SessionId = ""; + client->cSessionId = ""; client->status = WSC_NOT_CONNECTED; From 0aaf50f87f46ff6a4011ea83dd91e12d053d7bcf Mon Sep 17 00:00:00 2001 From: Markus Date: Fri, 6 Jan 2017 10:44:25 +0100 Subject: [PATCH 09/14] mask ping for client fix #34 --- src/WebSocketsClient.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WebSocketsClient.cpp b/src/WebSocketsClient.cpp index 0cb1f38..fbcb3a1 100644 --- a/src/WebSocketsClient.cpp +++ b/src/WebSocketsClient.cpp @@ -215,7 +215,7 @@ bool WebSocketsClient::sendBIN(const uint8_t * payload, size_t length) { */ bool WebSocketsClient::sendPing(uint8_t * payload, size_t length) { if(clientIsConnected(&_client)) { - return sendFrame(&_client, WSop_ping, payload, length); + return sendFrame(&_client, WSop_ping, payload, length, true); } return false; } From 60903a2fa5807ea38b26b33a82daeed8880b8e6d Mon Sep 17 00:00:00 2001 From: Markus Date: Fri, 6 Jan 2017 10:48:30 +0100 Subject: [PATCH 10/14] mask pong #34 --- src/WebSockets.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WebSockets.cpp b/src/WebSockets.cpp index 6e9c2af..18eb019 100644 --- a/src/WebSockets.cpp +++ b/src/WebSockets.cpp @@ -430,7 +430,7 @@ void WebSockets::handleWebsocketPayloadCb(WSclient_t * client, bool ok, uint8_t break; case WSop_ping: // send pong back - sendFrame(client, WSop_pong, payload, header->payloadLen); + sendFrame(client, WSop_pong, payload, header->payloadLen, true); break; case WSop_pong: DEBUG_WEBSOCKETS("[WS][%d][handleWebsocket] get pong (%s)\n", client->num, payload); From dac71c4c238b770b6beec816ae494c61bb3c4eb5 Mon Sep 17 00:00:00 2001 From: Markus Date: Sun, 8 Jan 2017 09:55:28 +0100 Subject: [PATCH 11/14] moving host header try to fix #159 --- src/WebSocketsClient.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/WebSocketsClient.cpp b/src/WebSocketsClient.cpp index fbcb3a1..91fee1d 100644 --- a/src/WebSocketsClient.cpp +++ b/src/WebSocketsClient.cpp @@ -427,6 +427,7 @@ void WebSocketsClient::sendHeader(WSclient_t * client) { transport = "&transport=websocket&sid=" + client->cSessionId; } handshake = "GET " + client->cUrl + transport + " HTTP/1.1\r\n" + "Host: " + _host + ":" + _port + "\r\n" "Connection: Upgrade\r\n" "Upgrade: websocket\r\n" "Sec-WebSocket-Version: 13\r\n" @@ -442,11 +443,11 @@ void WebSocketsClient::sendHeader(WSclient_t * client) { } else { handshake = "GET " + client->cUrl + "&transport=polling HTTP/1.1\r\n" + "Host: " + _host + ":" + _port + "\r\n" "Connection: keep-alive\r\n"; } - handshake += "Host: " + _host + ":" + _port + "\r\n" - "Origin: file://\r\n" + handshake += "Origin: file://\r\n" "User-Agent: arduino-WebSocket-Client\r\n"; if(client->base64Authorization.length() > 0) { From bef2541ede696f512b5efd0d31adb47700f43223 Mon Sep 17 00:00:00 2001 From: Markus Date: Sat, 21 Jan 2017 12:28:56 +0100 Subject: [PATCH 12/14] fix #162 missing isSocketIO init --- src/WebSocketsClient.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/WebSocketsClient.cpp b/src/WebSocketsClient.cpp index 91fee1d..e0019fd 100644 --- a/src/WebSocketsClient.cpp +++ b/src/WebSocketsClient.cpp @@ -63,6 +63,7 @@ void WebSocketsClient::begin(const char *host, uint16_t port, const char * url, _client.cVersion = 0; _client.base64Authorization = ""; _client.plainAuthorization = ""; + _client.isSocketIO = false; #ifdef ESP8266 randomSeed(RANDOM_REG32); From 6757b8b74c4f136fa6c760eab480f671506d5c1d Mon Sep 17 00:00:00 2001 From: nguyenhunga5 Date: Fri, 3 Feb 2017 13:30:20 +0700 Subject: [PATCH 13/14] Fix socket.io issue Fix socket.io issue reference from https://github.com/Links2004/arduinoWebSockets/issues/167#issuecomment-276724057 --- src/WebSocketsClient.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/WebSocketsClient.cpp b/src/WebSocketsClient.cpp index e0019fd..c526d96 100644 --- a/src/WebSocketsClient.cpp +++ b/src/WebSocketsClient.cpp @@ -507,7 +507,11 @@ void WebSocketsClient::handleHeader(WSclient_t * client, String * headerLine) { } else if(headerName.equalsIgnoreCase("Sec-WebSocket-Version")) { client->cVersion = headerValue.toInt(); } else if(headerName.equalsIgnoreCase("Set-Cookie")) { - client->cSessionId = headerValue.substring(headerValue.indexOf('=') + 1); + if (headerValue.indexOf("HttpOnly") > -1) { + client->cSessionId = headerValue.substring(headerValue.indexOf('=') + 1, headerValue.indexOf(";")); + } else { + client->cSessionId = headerValue.substring(headerValue.indexOf('=') + 1); + } } } else { DEBUG_WEBSOCKETS("[WS-Client][handleHeader] Header error (%s)\n", headerLine->c_str()); From f52d718cf23bae41c1f6cd6e7215f6879e0dede9 Mon Sep 17 00:00:00 2001 From: tzapu Date: Fri, 3 Feb 2017 13:53:46 +0200 Subject: [PATCH 14/14] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0394d98..6f2e5a4 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ a WebSocket Server and Client for Arduino based on RFC6455. This libary can run in Async TCP mode on the ESP. -The mode can be aktivated in the ```WebSockets.h``` (see WEBSOCKETS_NETWORK_TYPE define). +The mode can be activated in the ```WebSockets.h``` (see WEBSOCKETS_NETWORK_TYPE define). [ESPAsyncTCP](https://github.com/me-no-dev/ESPAsyncTCP) libary is required.