xtd - Reference Guide 0.2.0
tcp_client.h
Go to the documentation of this file.
1 #pragma once
5 
6 #include "../../object.h"
7 #include "../../ustring.h"
8 #include "../ip_end_point.h"
9 #include "network_stream.h"
10 #include "socket.h"
11 
13 namespace xtd {
15  namespace net {
17  namespace sockets {
19  class tcp_listener;
21 
44  class core_export_ tcp_client : public xtd::object {
45  public:
47 
52  tcp_client();
69  tcp_client(const xtd::ustring& hostname, uint16_t port);
71 
73  tcp_client(tcp_client&&) = default;
74  tcp_client(const tcp_client&) = default;
75  ~tcp_client();
76  tcp_client& operator=(const tcp_client&) = default;
77  friend std::ostream& operator <<(std::ostream& os, const tcp_client& tc) noexcept {return os << tc.to_string();}
78  bool operator==(const tcp_client& s) const {return data_ == s.data_;};
79  bool operator!=(const tcp_client& s) const {return !operator==(s);};
81 
83 
93  size_t available() const;
94 
101  xtd::net::sockets::socket client() const noexcept;
109  tcp_client& client(const xtd::net::sockets::socket& value) noexcept;
110 
119  bool connected() const noexcept;
120 
128  bool exclusive_address_use() const;
137  tcp_client& exclusive_address_use(bool value);
138 
155  xtd::net::sockets::linger_option linger_state() const;
173  tcp_client& linger_state(const xtd::net::sockets::linger_option& value);
174 
180  bool no_delay() const;
187  tcp_client& no_delay(bool value);
188 
196  size_t receive_buffer_size() const;
205  tcp_client& receive_buffer_size(size_t value);
206 
210  int32_t receive_timeout() const;
215  tcp_client& receive_timeout(int32_t value);
216 
222  size_t send_buffer_size() const;
229  tcp_client& send_buffer_size(size_t value);
230 
235  int32_t send_timeout() const;
241  tcp_client& send_timeout(int32_t value);
243 
245 
258  std::shared_ptr<xtd::iasync_result> begin_connect(const xtd::net::ip_address& address, uint16_t port, xtd::async_callback callback, const std::any& state);
270  std::shared_ptr<xtd::iasync_result> begin_connect(const std::vector<xtd::net::ip_address>& addresses, uint16_t port, xtd::async_callback callback, const std::any& state);
282  std::shared_ptr<xtd::iasync_result> begin_connect(const xtd::ustring& host, uint16_t port, xtd::async_callback callback, const std::any& state);
283 
289  void close();
290 
297  void connect(const xtd::net::ip_end_point& remote_end_point);
308  void connect(const xtd::net::ip_address& ip_address, uint16_t port);
317  void connect(const xtd::ustring& hostname, uint16_t port);
318 
326  void end_connect(std::shared_ptr<xtd::iasync_result> async_result);
327 
333  xtd::net::sockets::network_stream get_stream() const;
335 
336  protected:
338 
343  bool active() const noexcept;
348  tcp_client& active(bool value) noexcept;
350 
351  private:
352  friend tcp_listener;
354  struct data;
355  std::shared_ptr<data> data_;
356  };
357  }
358  }
359 }
Implements the Berkeley sockets interface.
Definition: socket.h:68
The xtd::uri::host data.
Provides the underlying stream of data for network access.
Definition: network_stream.h:34
virtual xtd::ustring to_string() const noexcept
Returns a sxd::ustring that represents the current object.
Provides an Internet Protocol (IP) address.
Definition: ip_address.h:34
Specifies whether a xtd::net::sockets::socket will remain connected after a call to the xtd::net::soc...
Definition: linger_option.h:31
Receive a time-out. This option applies only to synchronous methods; it has no effect on asynchronous...
Identifies a network address. This is an abstract class.
Definition: end_point.h:24
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
Enables a socket to be bound for exclusive access.
Represents a network endpoint as an IP address and a port number.
Definition: ip_end_point.h:20
delegate< void(std::shared_ptr< xtd::iasync_result > ar)> async_callback
References a method to be called when a corresponding asynchronous operation completes.
Definition: async_callback.h:18
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:50
Send a time-out. This option applies only to synchronous methods; it has no effect on asynchronous me...
Provides client connections for TCP network services.
Definition: tcp_client.h:44
Indicates that all styles except allow_binary_specifier, allow_octal_specifier and allow_hex_specifie...
The xtd::uri::port data.
Disables the Nagle algorithm for send coalescing.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes...
Definition: object.h:30
Contains xtd::net::sockets::network_stream class.
Contains xtd::net::sockets::socket class.
Listens for connections from TCP network clients.
Definition: tcp_listener.h:35
address_family
Specifies the addressing scheme that an instance of the xtd::net::sockets::socket class can use...
Definition: address_family.h:27