JSON-RPC 2.0
JSON-RPC 2.0 Modern C++ Library
Loading...
Searching...
No Matches
socket_transport.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <asio.hpp>
4#include <string>
5
7
8namespace jsonrpc::transport {
9
16class SocketTransport : public Transport {
17 public:
25 SocketTransport(const std::string &host, uint16_t port, bool is_server);
26
27 ~SocketTransport() override;
28
30 auto operator=(const SocketTransport &) -> SocketTransport & = delete;
31
34
35 void SendMessage(const std::string &message) override;
36 auto ReceiveMessage() -> std::string override;
37
38 protected:
39 auto GetSocket() -> asio::ip::tcp::socket &;
40
41 private:
42 void Connect();
43 void BindAndListen();
44
45 asio::io_context io_context_;
46 asio::ip::tcp::socket socket_;
47 std::string host_;
48 uint16_t port_;
49 bool is_server_;
50};
51
52} // namespace jsonrpc::transport
Transport implementation using TCP/IP sockets.
SocketTransport(const SocketTransport &)=delete
auto GetSocket() -> asio::ip::tcp::socket &
void SendMessage(const std::string &message) override
Sends a message in string to the transport layer.
SocketTransport(const std::string &host, uint16_t port, bool is_server)
Constructs a SocketTransport.
SocketTransport(SocketTransport &&)=delete
auto ReceiveMessage() -> std::string override
Receives a message from the transport layer.
auto operator=(const SocketTransport &) -> SocketTransport &=delete
auto operator=(SocketTransport &&) -> SocketTransport &=delete
Base class for JSON-RPC transport.
Definition transport.hpp:12