Skip to content

Commit

Permalink
Merge pull request #1 from anakod/master
Browse files Browse the repository at this point in the history
Test merge
  • Loading branch information
tavalin committed Jun 25, 2015
2 parents 255f537 + 81981ba commit 03613d3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 8 additions & 2 deletions Sming/SmingCore/Network/WebSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ bool WebSocket::initialize(HttpRequest& request, HttpResponse& response)
return true;
}

void WebSocket::send(const char* message, int length)
void WebSocket::send(const char* message, int length, wsFrameType type)
{
uint8_t frameHeader[16] = {0};
size_t headSize = sizeof(frameHeader);
wsMakeFrame(NULL, length, frameHeader, &headSize, WS_TEXT_FRAME);
wsMakeFrame(NULL, length, frameHeader, &headSize, type);
connection->write((char*)frameHeader, headSize, TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE);
connection->writeString(message, TCP_WRITE_FLAG_COPY);
connection->flush();
Expand All @@ -50,3 +50,9 @@ void WebSocket::sendString(const String& message)
{
send(message.c_str(), message.length());
}

void WebSocket::sendBinary(const uint8_t* data, int size)
{
send((char*)data, size, WS_BINARY_FRAME);
}

4 changes: 3 additions & 1 deletion Sming/SmingCore/Network/WebSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "../../Wiring/WHashMap.h"
#include "../../Wiring/WVector.h"
#include "../Delegate.h"
#include "../../Libraries/cWebsocket/websocket.h"

class HttpServer;

Expand All @@ -21,8 +22,9 @@ class WebSocket
friend class HttpServer;
public:
WebSocket(HttpServerConnection* conn);
virtual void send(const char* message, int length);
virtual void send(const char* message, int length, wsFrameType type = WS_TEXT_FRAME);
void sendString(const String& message);
void sendBinary(const uint8_t* data, int size);

protected:
bool initialize(HttpRequest &request, HttpResponse &response);
Expand Down

0 comments on commit 03613d3

Please sign in to comment.