Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add protocol support to WebSocketClient #121

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/WebSocketClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/WebSocketClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down