Goby v2
tcp_client.h
1 // Copyright 2009-2018 Toby Schneider (http://gobysoft.org/index.wt/people/toby)
2 // GobySoft, LLC (2013-)
3 // Massachusetts Institute of Technology (2007-2014)
4 // Community contributors (see AUTHORS file)
5 //
6 //
7 // This file is part of the Goby Underwater Autonomy Project Libraries
8 // ("The Goby Libraries").
9 //
10 // The Goby Libraries are free software: you can redistribute them and/or modify
11 // them under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 2.1 of the License, or
13 // (at your option) any later version.
14 //
15 // The Goby Libraries are distributed in the hope that they will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with Goby. If not, see <http://www.gnu.org/licenses/>.
22 
23 #ifndef TCPClientH
24 #define TCPClientH
25 
26 #include "client_base.h"
27 #include "goby/util/as.h"
28 
29 namespace goby
30 {
31 namespace util
32 {
34 class TCPClient : public LineBasedClient<boost::asio::ip::tcp::socket>
35 {
36  public:
42  TCPClient(const std::string& server, unsigned port, const std::string& delimiter = "\r\n",
43  int retry_interval = 10);
44 
45  boost::asio::ip::tcp::socket& socket() { return socket_; }
46 
48  std::string local_endpoint() { return goby::util::as<std::string>(socket_.local_endpoint()); }
50  std::string remote_endpoint() { return goby::util::as<std::string>(socket_.remote_endpoint()); }
51 
52  private:
53  bool start_specific();
54 
55  friend class TCPConnection;
56  friend class LineBasedConnection<boost::asio::ip::tcp::socket>;
57 
58  private:
59  boost::asio::ip::tcp::socket socket_;
60  std::string server_;
61  std::string port_;
62 };
63 } // namespace util
64 } // namespace goby
65 
66 #endif
std::string local_endpoint()
string representation of the local endpoint (e.g. 192.168.1.105:54230
Definition: tcp_client.h:48
std::string remote_endpoint()
string representation of the remote endpoint, (e.g. 192.168.1.106:50000
Definition: tcp_client.h:50
provides a basic TCP client for line by line text based communications to a remote TCP server ...
Definition: tcp_client.h:34
The global namespace for the Goby project.
TCPClient(const std::string &server, unsigned port, const std::string &delimiter="\r\n", int retry_interval=10)
create a TCPClient
Definition: tcp_client.cpp:28