Skip to content

Commit 56772a0

Browse files
committed
Add protocol support to WebSocketClient
1 parent 1751e10 commit 56772a0

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

Diff for: src/WebSocketClient.cpp

+15-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ WebSocketClient::WebSocketClient(Client& aClient, const IPAddress& aServerAddres
2626
{
2727
}
2828

29-
int WebSocketClient::begin(const char* aPath)
29+
int WebSocketClient::begin(const char* aPath, const char* protocol=NULL)
3030
{
3131
// start the GET request
3232
beginRequest();
@@ -51,6 +51,9 @@ int WebSocketClient::begin(const char* aPath)
5151
sendHeader("Connection", "Upgrade");
5252
sendHeader("Sec-WebSocket-Key", base64RandomKey);
5353
sendHeader("Sec-WebSocket-Version", "13");
54+
if (protocol) {
55+
sendHeader("Sec-WebSocket-Protocol", protocol);
56+
}
5457
endRequest();
5558

5659
status = responseStatusCode();
@@ -67,9 +70,19 @@ int WebSocketClient::begin(const char* aPath)
6770
return (status == 101) ? 0 : status;
6871
}
6972

73+
int WebSocketClient::begin(const String& aPath, const String& protocol)
74+
{
75+
return begin(aPath, protocol);
76+
}
77+
78+
int WebSocketClient::begin(const char* aPath)
79+
{
80+
return begin(aPath, NULL);
81+
}
82+
7083
int WebSocketClient::begin(const String& aPath)
7184
{
72-
return begin(aPath.c_str());
85+
return begin(aPath.c_str(), NULL);
7386
}
7487

7588
int WebSocketClient::beginMessage(int aType)

Diff for: src/WebSocketClient.h

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class WebSocketClient : public HttpClient
2828
*/
2929
int begin(const char* aPath = "/");
3030
int begin(const String& aPath);
31+
int begin(const char* aPath, const char* protocol);
32+
int begin(const String& aPath, const String& protocol);
3133

3234
/** Begin to send a message of type (TYPE_TEXT or TYPE_BINARY)
3335
Use the write or Stream API's to set message content, followed by endMessage

0 commit comments

Comments
 (0)