xtd 0.2.0
tcp_client.h
Go to the documentation of this file.
1 #pragma once
5 #include "network_stream.h"
6 #include "socket.h"
7 #include "../ip_end_point.h"
8 #include "../../iequatable.h"
9 #include "../../object.h"
10 #include "../../ustring.h"
11 
13 namespace xtd {
15  namespace net {
17  namespace sockets {
19  class tcp_listener;
21 
46  class core_export_ tcp_client : public xtd::object, public xtd::iequatable<tcp_client> {
47  struct data;
48 
49  public:
51 
56  tcp_client();
73  tcp_client(const xtd::ustring& hostname, uint16 port);
75 
77  tcp_client(tcp_client&&) = default;
78  tcp_client(const tcp_client&) = default;
79  ~tcp_client();
80  tcp_client& operator =(const tcp_client&) = default;
82 
84 
94  size_t available() const;
95 
102  xtd::net::sockets::socket client() const noexcept;
110  tcp_client& client(const xtd::net::sockets::socket& value) noexcept;
111 
120  bool connected() const noexcept;
121 
129  bool exclusive_address_use() const;
138  tcp_client& exclusive_address_use(bool value);
139 
156  xtd::net::sockets::linger_option linger_state() const;
174  tcp_client& linger_state(const xtd::net::sockets::linger_option& value);
175 
181  bool no_delay() const;
188  tcp_client& no_delay(bool value);
189 
197  size_t receive_buffer_size() const;
206  tcp_client& receive_buffer_size(size_t value);
207 
211  int32 receive_timeout() const;
217 
223  size_t send_buffer_size() const;
230  tcp_client& send_buffer_size(size_t value);
231 
236  int32 send_timeout() const;
242  tcp_client& send_timeout(int32 value);
244 
246 
259  std::shared_ptr<xtd::iasync_result> begin_connect(const xtd::net::ip_address& address, uint16 port, xtd::async_callback callback, const std::any& state);
271  std::shared_ptr<xtd::iasync_result> begin_connect(const std::vector<xtd::net::ip_address>& addresses, uint16 port, xtd::async_callback callback, const std::any& state);
283  std::shared_ptr<xtd::iasync_result> begin_connect(const xtd::ustring& host, uint16 port, xtd::async_callback callback, const std::any& state);
284 
290  void close();
291 
298  void connect(const xtd::net::ip_end_point& remote_end_point);
309  void connect(const xtd::net::ip_address& ip_address, uint16 port);
318  void connect(const xtd::ustring& hostname, uint16 port);
319 
327  void end_connect(std::shared_ptr<xtd::iasync_result> async_result);
328 
329  bool equals(const tcp_client& s) const noexcept override;
330 
336  xtd::net::sockets::network_stream get_stream() const;
338 
339  protected:
341 
346  bool active() const noexcept;
351  tcp_client& active(bool value) noexcept;
353 
354  private:
355  friend tcp_listener;
357 
358  std::shared_ptr<data> data_;
359  };
360  }
361  }
362 }
Implements the Berkeley sockets interface.
Definition: socket.h:71
The xtd::uri::host data.
Provides the underlying stream of data for network access.
Definition: network_stream.h:35
Provides an Internet Protocol (IP) address.
Definition: ip_address.h:35
delegate< void(async_result ar)> async_callback
References a method to be called when a corresponding asynchronous operation completes.
Definition: delegate.h:34
Specifies whether a xtd::net::sockets::socket will remain connected after a call to the xtd::net::soc...
Definition: linger_option.h:32
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:25
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
std::shared_ptr< xtd::iasync_result > async_result
Represents the status of an asynchronous operation.
Definition: async_result.h:16
Enables a socket to be bound for exclusive access.
uint_least16_t uint16
Represents a 16-bit unsigned integer.
Definition: types.h:228
Represents a network endpoint as an IP address and a port number.
Definition: ip_end_point.h:21
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:46
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:46
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition: iequatable.h:18
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:32
Contains xtd::net::sockets::network_stream class.
int_least32_t int32
Represents a 32-bit signed integer.
Definition: types.h:129
Contains xtd::net::sockets::socket class.
Listens for connections from TCP network clients.
Definition: tcp_listener.h:38
address_family
Specifies the addressing scheme that an instance of the xtd::net::sockets::socket class can use...
Definition: address_family.h:28