diff --git a/src/WebSocketClient.cpp b/src/WebSocketClient.cpp index ab41b0a..1a50b03 100644 --- a/src/WebSocketClient.cpp +++ b/src/WebSocketClient.cpp @@ -26,7 +26,7 @@ WebSocketClient::WebSocketClient(Client& aClient, const IPAddress& aServerAddres { } -int WebSocketClient::begin(const char* aPath) +int WebSocketClient::begin(const char* aPath, const char* protocol=NULL) { // start the GET request beginRequest(); @@ -51,6 +51,9 @@ int WebSocketClient::begin(const char* aPath) sendHeader("Connection", "Upgrade"); sendHeader("Sec-WebSocket-Key", base64RandomKey); sendHeader("Sec-WebSocket-Version", "13"); + if (protocol) { + sendHeader("Sec-WebSocket-Protocol", protocol); + } endRequest(); status = responseStatusCode(); @@ -67,9 +70,19 @@ int WebSocketClient::begin(const char* aPath) return (status == 101) ? 0 : status; } +int WebSocketClient::begin(const String& aPath, const String& protocol) +{ + return begin(aPath, protocol); +} + +int WebSocketClient::begin(const char* aPath) +{ + return begin(aPath, NULL); +} + int WebSocketClient::begin(const String& aPath) { - return begin(aPath.c_str()); + return begin(aPath.c_str(), NULL); } int WebSocketClient::beginMessage(int aType) diff --git a/src/WebSocketClient.h b/src/WebSocketClient.h index 4b009e6..695d691 100644 --- a/src/WebSocketClient.h +++ b/src/WebSocketClient.h @@ -28,6 +28,8 @@ class WebSocketClient : public HttpClient */ int begin(const char* aPath = "/"); int begin(const String& aPath); + int begin(const char* aPath, const char* protocol); + int begin(const String& aPath, const String& protocol); /** Begin to send a message of type (TYPE_TEXT or TYPE_BINARY) Use the write or Stream API's to set message content, followed by endMessage