24 #ifndef GOBY_MIDDLEWARE_IO_DETAIL_TCP_CLIENT_INTERFACE_H
25 #define GOBY_MIDDLEWARE_IO_DETAIL_TCP_CLIENT_INTERFACE_H
33 #include <boost/asio/ip/tcp.hpp>
53 PubSubLayer subscribe_layer,
typename Config,
template <
class>
class ThreadType,
54 bool use_indexed_groups =
false>
56 :
public IOThread<line_in_group, line_out_group, publish_layer, subscribe_layer, Config,
57 boost::asio::ip::tcp::socket, ThreadType, use_indexed_groups>
59 using Base =
IOThread<line_in_group, line_out_group, publish_layer, subscribe_layer, Config,
60 boost::asio::ip::tcp::socket, ThreadType, use_indexed_groups>;
62 using ConfigType = Config;
69 std::string(
"tcp: ") +
config.remote_address() +
":" +
72 boost::asio::ip::tcp::resolver resolver(this->
mutable_io());
73 remote_endpoint_ = *resolver.resolve(
74 {this->cfg().remote_address(),
std::to_string(this->cfg().remote_port()),
75 boost::asio::ip::resolver_query_base::numeric_service});
78 this->interthread().template publish<line_in_group>(ready);
83 auto event = std::make_shared<goby::middleware::protobuf::TCPClientEvent>();
84 if (this->index() != -1)
85 event->set_index(this->index());
87 *
event->mutable_local_endpoint() = endpoint_convert<protobuf::TCPEndPoint>(local_endpoint_);
88 *
event->mutable_remote_endpoint() =
89 endpoint_convert<protobuf::TCPEndPoint>(remote_endpoint_);
91 <<
"Event: " <<
event->ShortDebugString() << std::endl;
92 this->publish_in(event);
98 *io_msg->
mutable_tcp_src() = endpoint_convert<protobuf::TCPEndPoint>(remote_endpoint_);
99 *io_msg->
mutable_tcp_dest() = endpoint_convert<protobuf::TCPEndPoint>(local_endpoint_);
103 void async_write(std::shared_ptr<const goby::middleware::protobuf::IOData> io_msg)
override
109 void open_socket()
override
113 auto event = std::make_shared<goby::middleware::protobuf::TCPClientEvent>();
114 if (this->index() != -1)
115 event->set_index(this->index());
117 *
event->mutable_local_endpoint() = endpoint_convert<protobuf::TCPEndPoint>(local_endpoint_);
118 *
event->mutable_remote_endpoint() =
119 endpoint_convert<protobuf::TCPEndPoint>(remote_endpoint_);
121 <<
"Event: " <<
event->ShortDebugString() << std::endl;
122 this->publish_in(event);
128 boost::asio::ip::tcp::endpoint remote_endpoint_;
129 boost::asio::ip::tcp::endpoint local_endpoint_;