@@ -63,6 +63,7 @@ void WebSocketsClient::begin(const char *host, uint16_t port, const char * url,
63
63
_client.cVersion = 0 ;
64
64
_client.base64Authorization = " " ;
65
65
_client.plainAuthorization = " " ;
66
+ _client.isSocketIO = false ;
66
67
67
68
#ifdef ESP8266
68
69
randomSeed (RANDOM_REG32);
@@ -207,6 +208,24 @@ bool WebSocketsClient::sendBIN(const uint8_t * payload, size_t length) {
207
208
return sendBIN ((uint8_t *) payload, length);
208
209
}
209
210
211
+ /* *
212
+ * sends a WS ping to Server
213
+ * @param payload uint8_t *
214
+ * @param length size_t
215
+ * @return true if ping is send out
216
+ */
217
+ bool WebSocketsClient::sendPing (uint8_t * payload, size_t length) {
218
+ if (clientIsConnected (&_client)) {
219
+ return sendFrame (&_client, WSop_ping, payload, length, true );
220
+ }
221
+ return false ;
222
+ }
223
+
224
+ bool WebSocketsClient::sendPing (String & payload) {
225
+ return sendPing ((uint8_t *) payload.c_str (), payload.length ());
226
+ }
227
+
228
+
210
229
/* *
211
230
* disconnect one client
212
231
* @param num uint8_t client id
@@ -313,6 +332,7 @@ void WebSocketsClient::clientDisconnect(WSclient_t * client) {
313
332
client->cVersion = 0 ;
314
333
client->cIsUpgrade = false ;
315
334
client->cIsWebsocket = false ;
335
+ client->cSessionId = " " ;
316
336
317
337
client->status = WSC_NOT_CONNECTED;
318
338
@@ -411,8 +431,6 @@ void WebSocketsClient::sendHeader(WSclient_t * client) {
411
431
" Host: " + _host + " :" + _port + " \r\n "
412
432
" Connection: Upgrade\r\n "
413
433
" Upgrade: websocket\r\n "
414
- " Origin: file://\r\n "
415
- " User-Agent: arduino-WebSocket-Client\r\n "
416
434
" Sec-WebSocket-Version: 13\r\n "
417
435
" Sec-WebSocket-Key: " + client->cKey + " \r\n " ;
418
436
@@ -426,11 +444,11 @@ void WebSocketsClient::sendHeader(WSclient_t * client) {
426
444
427
445
} else {
428
446
handshake = " GET " + client->cUrl + " &transport=polling HTTP/1.1\r\n "
447
+ " Host: " + _host + " :" + _port + " \r\n "
429
448
" Connection: keep-alive\r\n " ;
430
449
}
431
450
432
- handshake += " Host: " + _host + " :" + _port + " \r\n "
433
- " Origin: file://\r\n "
451
+ handshake += " Origin: file://\r\n "
434
452
" User-Agent: arduino-WebSocket-Client\r\n " ;
435
453
436
454
if (client->base64Authorization .length () > 0 ) {
@@ -443,6 +461,7 @@ void WebSocketsClient::sendHeader(WSclient_t * client) {
443
461
444
462
handshake += " \r\n " ;
445
463
464
+ DEBUG_WEBSOCKETS (" [WS-Client][sendHeader] handshake %s" , (uint8_t *)handshake.c_str ());
446
465
client->tcp ->write ((uint8_t *)handshake.c_str (), handshake.length ());
447
466
448
467
#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC)
@@ -489,7 +508,11 @@ void WebSocketsClient::handleHeader(WSclient_t * client, String * headerLine) {
489
508
} else if (headerName.equalsIgnoreCase (" Sec-WebSocket-Version" )) {
490
509
client->cVersion = headerValue.toInt ();
491
510
} else if (headerName.equalsIgnoreCase (" Set-Cookie" )) {
492
- client->cSessionId = headerValue.substring (headerValue.indexOf (' =' ) + 1 );
511
+ if (headerValue.indexOf (" HttpOnly" ) > -1 ) {
512
+ client->cSessionId = headerValue.substring (headerValue.indexOf (' =' ) + 1 , headerValue.indexOf (" ;" ));
513
+ } else {
514
+ client->cSessionId = headerValue.substring (headerValue.indexOf (' =' ) + 1 );
515
+ }
493
516
}
494
517
} else {
495
518
DEBUG_WEBSOCKETS (" [WS-Client][handleHeader] Header error (%s)\n " , headerLine->c_str ());
0 commit comments