8000 Merge pull request #43 from brtiberio/master · coderGods/arduinoWebSockets@005441d · GitHub
[go: up one dir, main page]

Skip to content

Commit 005441d

Browse files
committed
Merge pull request Links2004#43 from brtiberio/master
add possibilty to define subprotocol of websockets client
2 parents ece771a + 358d8c7 commit 005441d

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

src/WebSockets.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
#include <Arduino.h>
2929

30-
//#define DEBUG_WEBSOCKETS(...) Serial1.printf( __VA_ARGS__ )
30+
//#define DEBUG_WEBSOCKETS(...) Serial.printf( __VA_ARGS__ )
3131

3232
#ifndef DEBUG_WEBSOCKETS
3333
#define DEBUG_WEBSOCKETS(...)

src/WebSocketsClient.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ WebSocketsClient::~WebSocketsClient() {
3737
/**
3838
* calles to init the Websockets server
3939
*/
40-
void WebSocketsClient::begin(const char *host, uint16_t port, const char * url) {
40+
void WebSocketsClient::begin(const char *host, uint16_t port, const char * url, const char * Protocol) {
4141
_host = host;
4242
_port = port;
4343
_fingerprint = "";
@@ -55,7 +55,7 @@ void WebSocketsClient::begin(const char *host, uint16_t port, const char * url)
5555
_client.cIsWebsocket = true;
5656
_client.cKey = "";
5757
_client.cAccept = "";
58-
_client.cProtocol = "";
58+
_client.cProtocol = Protocol;
5959
_client.cExtensions = "";
6060
_client.cVersion = 0;
6161

@@ -67,19 +67,19 @@ void WebSocketsClient::begin(const char *host, uint16_t port, const char * url)
6767
#endif
6868
}
6969

70-
void WebSocketsClient::begin(String host, uint16_t port, String url) {
71-
begin(host.c_str(), port, url.c_str());
70+
void WebSocketsClient::begin(String host, uint16_t port, String url, String Protocol) {
71+
begin(host.c_str(), port, url.c_str(), Protocol.c_str());
7272
}
7373

7474
#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266)
75-
void WebSocketsClient::beginSSL(const char *host, uint16_t port, const char * url, const char * fingerprint) {
76-
begin(host, port, url);
75+
void WebSocketsClient::beginSSL(const char *host, uint16_t port, const char * url, const char * fingerprint, const char * Protocol) {
76+
begin(host, port, url, Protocol);
7777
_client.isSSL = true;
7878
_fingerprint = fingerprint;
7979
}
8080

81-
void WebSocketsClient::beginSSL(String host, uint16_t port, String url, String fingerprint) {
82-
beginSSL(host.c_str(), port, url.c_str(), fingerprint.c_str());
81+
void WebSocketsClient::beginSSL(String host, uint16_t port, String url, String fingerprint, String Protocol) {
82+
beginSSL(host.c_str(), port, url.c_str(), fingerprint.c_str(), Protocol.c_str());
8383
}
8484
#endif
8585

@@ -366,7 +366,7 @@ void WebSocketsClient::sendHeader(WSclient_t * client) {
366366
"Connection: Upgrade\r\n"
367367
"User-Agent: arduino-WebSocket-Client\r\n"
368368
"Sec-WebSocket-Version: 13\r\n"
369-
"Sec-WebSocket-Protocol: arduino\r\n"
369+
"Sec-WebSocket-Protocol:" + client->cProtocol +"\r\n"
370370
"Sec-WebSocket-Key: " + client->cKey + "\r\n";
371371

372372
if(client->cExtensions.length() > 0) {

src/WebSocketsClient.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ class WebSocketsClient: private WebSockets {
3636
WebSocketsClient(void);
3737
~WebSocketsClient(void);
3838

39-
void begin(const char *host, uint16_t port, const char * url = "/");
40-
void begin(String host, uint16_t port, String url = "/");
39+
void begin(const char *host, uint16_t port, const char * url = "/", const char * Protocol = "arduino");
40+
void begin(String host, uint16_t port, String url = "/", String Protocol = "arduino");
4141

4242
#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266)
43-
void beginSSL(const char *host, uint16_t port, const char * url = "/", const char * = "");
44-
void beginSSL(String host, uint16_t port, String url = "/", String fingerprint = "");
43+
void beginSSL(const char *host, uint16_t port, const char * url = "/", const char * = "", const char * Protocol = "arduino");
44+
void beginSSL(String host, uint16_t port, String url = "/", String fingerprint = "", String Protocol = "arduino");
4545
#endif
4646

4747
void loop(void);

0 commit comments

Comments
 (0)
0