BF2MC-Matchmaker
websocket/client.h
1 #ifndef WEBSOCKET_CLIENT_H
2 #define WEBSOCKET_CLIENT_H
3 
4 #include <net/socket.h>
5 #include <util.h>
6 
7 // Forward declair
8 namespace atomizes
9 {
10  class HTTPMessage;
11 };
12 
13 namespace Json
14 {
15  class Value;
16 };
17 
18 /*
19  https://en.wikipedia.org/wiki/WebSocket
20 */
21 namespace Websocket
22 {
23  class Client : public Net::Socket
24  {
25  public:
26  Client(int socket, struct sockaddr_in address);
27  ~Client();
28 
29  void Listen();
30  void Disconnect();
31  void Send(const atomizes::HTTPMessage& http_response) const;
32  void Send(const Json::Value &value) const;
33 
34  /*
35  Events
36  */
37  void onRequest(const std::vector<char>& buffer);
38 
39  /*
40  Requests
41  */
42 
43 
44  private:
45  void _LogTransaction(const std::string& direction, const std::string& response) const;
46  std::string _GetSocketAcceptKey(const std::string& websocket_key);
47  std::vector<char> _UnmaskPayload(const std::vector<char>& key, const std::vector<char>& payload);
48  };
49 }
50 
51 #endif // WEBSOCKET_CLIENT_H
A base class representing a network socket.
Definition: socket.h:15