algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
Loading...
Searching...
No Matches
ws_session.hpp
1#pragma once
2
3#include "./ws_session_base.hpp"
4
5namespace algotradelib::network {
6
12class WsSession : public WebSocketSessionBase<WsSession, websocket::stream<beast::tcp_stream>> {
13public:
23 net::io_context& ioc,
24 std::string host,
25 std::string port,
26 std::string target = "/",
27 std::map<std::string, std::string> headers = {}
28 )
30 ioc,
31 std::move(host),
32 std::move(port),
33 WebSocketSessionOptions{std::move(target), std::move(headers)}
34 ) {}
35
36private:
37 template <typename, typename>
38 friend class WebSocketSessionBase;
39 friend struct WebSocketSessionTestAccess;
40 using Stream = websocket::stream<beast::tcp_stream>;
41
42 void do_connect() {
44 return;
45 }
46 ws_ = std::make_unique<Stream>(strand_);
47 buffer_.consume(buffer_.size());
49 }
50
51 void on_connect(beast::error_code error, tcp::resolver::results_type::endpoint_type endpoint) {
52 if (error) {
53 fail("connect", error);
54 return;
55 }
56 if (abandon_if_closing()) {
57 return;
58 }
59 host_header_ = host_ + ":" + std::to_string(endpoint.port());
61 }
62};
63
64} // namespace algotradelib::network
The base of the WebSocket clients WsSession and WssSession: connecting, sending, receiving,...
WsSession(net::io_context &ioc, std::string host, std::string port, std::string target="/", std::map< std::string, std::string > headers={})
Constructs a session.
HTTP and WebSocket transport, OAuth tokens, and request pacing.
Options for a WebSocket session (WsSession, WssSession).