xtd - Reference Guide  0.2.0
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
Go to the documentation of this file.
1 #pragma once
6 #include "../../object.h"
7 #include "../../ustring.h"
8 #include "../ip_end_point.h"
9 #include "network_stream.h"
10 #include "socket.h"
13 namespace xtd {
15  namespace net {
17  namespace sockets {
19  class tcp_listener;
39  class tcp_client : public xtd::object {
40  public:
44  tcp_client();
61  tcp_client(const xtd::ustring& hostname, uint16_t port);
64  tcp_client(tcp_client&&) = default;
65  tcp_client(const tcp_client&) = default;
66  ~tcp_client();
67  tcp_client& operator=(const tcp_client&) = default;
68  friend std::ostream& operator <<(std::ostream& os, const tcp_client& tc) noexcept {return os << tc.to_string();}
69  bool operator==(const tcp_client& s) const {return data_ == s.data_;};
70  bool operator!=(const tcp_client& s) const {return !operator==(s);};
81  size_t available() const;
89  xtd::net::sockets::socket client() const noexcept;
97  tcp_client& client(const xtd::net::sockets::socket& value) noexcept;
107  bool connected() const noexcept;
116  bool exclusive_address_use() const;
125  tcp_client& exclusive_address_use(bool value);
168  bool no_delay() const;
175  tcp_client& no_delay(bool value);
184  size_t receive_buffer_size() const;
193  tcp_client& receive_buffer_size(size_t value);
198  int32_t receive_timeout() const;
203  tcp_client& receive_timeout(int32_t value);
210  size_t send_buffer_size() const;
217  tcp_client& send_buffer_size(size_t value);
223  int32_t send_timeout() const;
229  tcp_client& send_timeout(int32_t value);
242  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);
254  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);
266  std::shared_ptr<xtd::iasync_result> begin_connect(const xtd::ustring& host, uint16_t port, xtd::async_callback callback, const std::any& state);
273  void close();
281  void connect(const xtd::net::ip_end_point& remote_end_point);
292  void connect(const xtd::net::ip_address& ip_address, uint16_t port);
301  void connect(const xtd::ustring& hostname, uint16_t port);
310  void end_connect(std::shared_ptr<xtd::iasync_result> async_result);
319  protected:
323  bool active() const noexcept;
328  tcp_client& active(bool value) noexcept;
330  private:
331  friend tcp_listener;
333  struct data;
334  std::shared_ptr<data> data_;
335  };
336  }
337  }
338 }
Initializes a new instance of the xtd::net::sockets::tcp_client class.
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)
Begins an asynchronous request for a remote host connection. The remote host is specified by an xtd::...
Implements the Berkeley sockets interface.
Definition: socket.h:63
Provides the underlying stream of data for network access.
Definition: network_stream.h:29
bool exclusive_address_use() const
Gets a bool value that specifies whether the xtd::net::sockets::tcp_client allows only one client to ...
virtual xtd::ustring to_string() const noexcept
Returns a std::string that represents the current object.
Provides an Internet Protocol (IP) address.
Definition: ip_address.h:30
Specifies whether a xtd::net::sockets::socket will remain connected after a call to the xtd::net::soc...
Definition: linger_option.h:26
void connect(const xtd::net::ip_end_point &remote_end_point)
Connects the client to a remote TCP host using the specified remote network endpoint.
size_t send_buffer_size() const
Gets the size of the send buffer.
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
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:48
Provides client connections for TCP network services.
Definition: tcp_client.h:39
size_t available() const
Gets the amount of data that has been received from the network and is available to be read...
xtd::net::sockets::socket client() const noexcept
Gets the underlying network xtd::net::sockets::socket.
xtd::net::sockets::linger_option linger_state() const
Gets a value that specifies whether the xtd::net::sockets::socket will delay closing a socket in an a...
xtd::net::sockets::network_stream get_stream() const
Returns the xtd::net::sockets::network_stream used to send and receive data.
bool no_delay() const
Gets a value that disables a delay when send or receive buffers are not full.
bool active() const noexcept
Gets a value that indicates whether a connection has been made.
bool connected() const noexcept
Gets a value indicating whether the underlying xtd::net::sockets::socket for a xtd::net::sockets::tcp...
Indicates that all styles except allow_binary_specifier, allow_octal_specifier and allow_hex_specifie...
int32_t send_timeout() const
Gets the amount of time a xtd::net::sockets::tcp_client will wait for a send operation to complete su...
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes...
Definition: object.h:26
Contains xtd::net::sockets::network_stream class.
size_t receive_buffer_size() const
Gets the size of the receive buffer.
Contains xtd::net::sockets::socket class.
int32_t receive_timeout() const
Gets the amount of time a xtd::net::sockets::tcp_client will wait to receive data once a read operati...
void close()
Disposes this xtd::net::sockets::tcp_client instance and requests that the underlying TCP connection ...
Listens for connections from TCP network clients.
Definition: tcp_listener.h:30
Specifies the addressing scheme that an instance of the xtd::net::sockets::socket class can use...
Definition: address_family.h:24
void end_connect(std::shared_ptr< xtd::iasync_result > async_result)
Ends a pending asynchronous connection attempt.