xtd - Reference Guide  0.1.2
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
Loading...
Searching...
No Matches
tcp_client.h
Go to the documentation of this file.
1
4#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
13namespace xtd {
15 namespace net {
17 namespace sockets {
19 class tcp_listener;
21
39 class tcp_client : public xtd::object {
40 public:
61 tcp_client(const xtd::ustring& hostname, uint16_t port);
62
64 tcp_client(tcp_client&&) = default;
65 tcp_client(const tcp_client&) = default;
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);};
72
81 size_t available() const;
82
97 tcp_client& client(const xtd::net::sockets::socket& value) noexcept;
98
107 bool connected() const noexcept;
108
126
143 xtd::net::sockets::linger_option linger_state() const;
161 tcp_client& linger_state(const xtd::net::sockets::linger_option& value);
162
168 bool no_delay() const;
175 tcp_client& no_delay(bool value);
176
184 size_t receive_buffer_size() const;
194
198 int32_t receive_timeout() const;
204
210 size_t send_buffer_size() const;
218
223 int32_t send_timeout() const;
229 tcp_client& send_timeout(int32_t value);
230
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);
267
273 void close();
274
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);
302
310 void end_connect(std::shared_ptr<xtd::iasync_result> async_result);
311
317 xtd::net::sockets::network_stream get_stream() const;
318
319 protected:
323 bool active() const noexcept;
328 tcp_client& active(bool value) noexcept;
329
330 private:
331 friend tcp_listener;
332 tcp_client(const xtd::net::sockets::socket& socket);
333 struct data;
334 std::shared_ptr<data> data_;
335 };
336 }
337 }
338}
Represents the status of an asynchronous operation.
Definition iasync_result.h:21
Identifies a network address. This is an abstract class.
Definition end_point.h:24
Provides an Internet Protocol (IP) address.
Definition ip_address.h:30
Represents a network endpoint as an IP address and a port number.
Definition ip_end_point.h:20
Specifies whether a xtd::net::sockets::socket will remain connected after a call to the xtd::net::soc...
Definition linger_option.h:26
Provides the underlying stream of data for network access.
Definition network_stream.h:29
Implements the Berkeley sockets interface.
Definition socket.h:63
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::network_stream get_stream() const
Returns the xtd::net::sockets::network_stream used to send and receive data.
bool exclusive_address_use() const
Gets a bool value that specifies whether the xtd::net::sockets::tcp_client allows only one client to ...
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::...
void close()
Disposes this xtd::net::sockets::tcp_client instance and requests that the underlying TCP connection ...
xtd::net::sockets::socket client() const noexcept
Gets the underlying network xtd::net::sockets::socket.
bool connected() const noexcept
Gets a value indicating whether the underlying xtd::net::sockets::socket for a xtd::net::sockets::tcp...
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...
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...
tcp_client()
Initializes a new instance of the xtd::net::sockets::tcp_client class.
size_t send_buffer_size() const
Gets the size of the send buffer.
tcp_client(const xtd::net::ip_end_point &end_point)
Initializes a new instance of the xtd::net::sockets::tcp_client class and binds it to the specified l...
tcp_client(xtd::net::sockets::address_family address_family)
The xtd::net::sockets::address_family of the IP protocol.
bool active() const noexcept
Gets a value that indicates whether a connection has been made.
bool no_delay() const
Gets a value that disables a delay when send or receive buffers are not full.
void end_connect(std::shared_ptr< xtd::iasync_result > async_result)
Ends a pending asynchronous connection attempt.
tcp_client(const xtd::ustring &hostname, uint16_t port)
Initializes a new instance of the xtd::net::sockets::tcp_client class and connects to the specified p...
size_t receive_buffer_size() const
Gets the size of the receive buffer.
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...
Listens for connections from TCP network clients.
Definition tcp_listener.h:30
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.h:26
virtual xtd::ustring to_string() const noexcept
Returns a std::string that represents the current object.
Represents text as a sequence of UTF-8 code units.
Definition ustring.h:48
address_family
Specifies the addressing scheme that an instance of the xtd::net::sockets::socket class can use.
Definition address_family.h:24
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
@ any
Indicates that all styles except allow_binary_specifier, allow_octal_specifier and allow_hex_specifie...
@ connect
A socket connect operation.
@ s
The S key.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition system_report.h:17
Contains xtd::net::sockets::network_stream class.
Contains xtd::net::sockets::socket class.