-
Notifications
You must be signed in to change notification settings - Fork 0
Build software based on WebSocket++
Building a program using WebSocket++ has two parts:
This is done by subclassing websocketpp::connection_handler
. Each websocket connection is attached to a connection handler. The handler implements the following methods:
Called after the client handshake is received but before the connection is accepted. Allows cookie authentication, origin checking, subprotocol negotiation, etc.
Called when the connection has been established and writes are allowed.
Called when the connection has been disconnected.
Called when a new websocket message is received.
The handler has access to the following websocket session API methods:
returns the value of an HTTP header sent by the client during the handshake
returns the resource requested by the client in the handshake
pass responsibility for this connection to another connection handler
reject the connection with a specific HTTP error
adds an HTTP header to the server handshake
selects a subprotocol for the connection
send a websocket message
send a ping
There are two example programs in the examples directory that demonstrate this use pattern. One is a trivial stateless echo server, the other is a simple web based chat client. Both include example javascript clients. The echo server is suitable for use with automated testing suites such as the Autobahn test suite.
By default, a single connection handler object is used for all connections. If needs require, that default handler can either store per-connection state itself or create new handlers and pass off responsibility for the connection to them.