5#ifndef PT_HTTP_API_WEBSOCKETCLIENT_H
6#define PT_HTTP_API_WEBSOCKETCLIENT_H
44 socket.connected() +=
Pt::slot(onConnected);
45 socket.closed() +=
Pt::slot(onClosed);
46 socket.setTimeout(10000);
47 socket.beginConnect(
"/ws");
51 Construct %WebSocket with the %Client that performs the
52 handshake.
Connect %connected() and call %beginConnect() with a
53 request path, or with a %ws:
54 already the client's endpoint. The path and query of that URL
55 become the request URL; the client does not take the host from
56 the URL. The optional second argument is the Origin header.
57 %beginConnect() fills a GET with Connection, Upgrade,
58 Sec-WebSocket-Version 13 and Sec-WebSocket-Key, and sends it
59 through the client. A finished 101 becomes the stream this
60 socket formats. %endConnect() completes the handshake and throws
61 if it failed. After that success the socket no longer uses the
62 client for messages. A client masks every frame it writes.
64 %closed() is emitted while this socket is still alive. The
65 stream has already cleared its session pointer. Peer close, an
66 I/O error, a close frame and destruction of the stream all emit
67 it. It ends an outstanding send or receive. The owner deletes
68 this socket. %setTimeout() bounds I/O after the upgrade. The
69 handshake still uses the timeout of the client.
HTTP user agent.
Definition Client.h:195
Client handshake and messages on an upgraded stream.
Definition WebSocket.h:133
Host and service address.
Definition Endpoint.h:77
ConstMethodSlot< R, ClassT, As... > slot(ClassT &object, R(BaseT::*method)(As...) const)
Returns a slot object for the given object/member pair.
Definition ConstMethod.h:172
void run()
Starts the loop.
Platform event loop.
Definition MainLoop.h:51
@ Connect
Client handshake.
Definition Context.h:57