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, std::string host, std::string port, std::string target = "/",
24 std::map<std::string, std::string> headers = {}
25 )
27 ioc, std::move(host), std::move(port), WebSocketSessionOptions{std::move(target), std::move(headers)}
28 ) {}
29
30private:
31 template <typename, typename>
32 friend class WebSocketSessionBase;
33 friend struct WebSocketSessionTestAccess;
34 using Stream = websocket::stream<beast::tcp_stream>;
35
36 void do_connect() {
38 return;
39 }
40 ws_ = std::make_unique<Stream>(strand_);
41 buffer_.consume(buffer_.size());
43 }
44
45 void on_connect(beast::error_code error, tcp::resolver::results_type::endpoint_type endpoint) {
46 if (error) {
47 fail("connect", error);
48 return;
49 }
50 if (abandon_if_closing()) {
51 return;
52 }
53 host_header_ = host_ + ":" + std::to_string(endpoint.port());
55 }
56};
57
58} // 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).