Skip to content
muhler edited this page Nov 23, 2011 · 1 revision

The Session API allows a handler to look up information about a session as well as interact with that session (send messages, close the connection, etc).

Session pointers are returned with every handler callback as well as every call to websocketpp::client::connect().

Handler Interface:

  • set_handler(connection_handler_ptr)

Handshake Interface:
For the client these methods are valid after the server’s handshake has been received. This is guaranteed to be the case by the time on_open() is called.
For the server these methods are valid after the client’s handshake has been received. This is guaranteed to be the case by the time validate() is called.

  • const std::string& get_subprotocol() const;
  • const std::string& get_resource() const;
  • const std::string& get_origin() const;
  • std::string get_client_header(const std::string&) const;
  • std::string get_server_header(const std::string&) const;
  • const std::vector<std::string>& get_extensions() const;
  • unsigned int get_version() const;

Frame Interface

  • void send(const std::string &);
  • void send(const std::vector<unsigned char> &);
  • void ping(const std::string &);
  • void pong(const std::string &);

These methods are valid only for open connections. They will throw an exception if called from any other state.

WebSocket++ does not queue messages. As such only one send operation can be occurring at once.

Session Interface

  • void close(uint16_t status,const std::string &reason);
  • bool is_server() const;