xtd - Reference Guide
0.1.1
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
|
#include <tcp_client.h>
Provides client connections for TCP network services.
Inherits xtd::object.
Public Member Functions | |
tcp_client () | |
Initializes a new instance of the xtd::net::sockets::tcp_client class. More... | |
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 local endpoint. More... | |
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 port on the specified host. More... | |
tcp_client (xtd::net::sockets::address_family address_family) | |
The xtd::net::sockets::address_family of the IP protocol. More... | |
size_t | available () const |
Gets the amount of data that has been received from the network and is available to be read. More... | |
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) |
Begins an asynchronous request for a remote host connection. The remote host is specified by an xtd::net::ip_address array and a port number (uint16_t). More... | |
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::net::ip_address and a port number (uint16_t). More... | |
std::shared_ptr< xtd::iasync_result > | begin_connect (const xtd::ustring &host, 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 a host name (xtd::ustring) and a port number (uint16_t). More... | |
xtd::net::sockets::socket | client () const noexcept |
Gets the underlying network xtd::net::sockets::socket. More... | |
tcp_client & | client (const xtd::net::sockets::socket &value) noexcept |
Sets the underlying network xtd::net::sockets::socket. More... | |
void | close () |
Disposes this xtd::net::sockets::tcp_client instance and requests that the underlying TCP connection be closed. More... | |
void | connect (const xtd::net::ip_address &ip_address, uint16_t port) |
Connects the client to a remote TCP host using the specified IP address and port number. More... | |
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. More... | |
void | connect (const xtd::ustring &hostname, uint16_t port) |
Connects the client to the specified port on the specified host. More... | |
bool | connected () const noexcept |
Gets a value indicating whether the underlying xtd::net::sockets::socket for a xtd::net::sockets::tcp_client is connected to a remote host. More... | |
void | end_connect (std::shared_ptr< xtd::iasync_result > async_result) |
Ends a pending asynchronous connection attempt. More... | |
bool | exclusive_address_use () const |
Gets a bool value that specifies whether the xtd::net::sockets::tcp_client allows only one client to use a port. More... | |
tcp_client & | exclusive_address_use (bool value) |
Sets a bool value that specifies whether the xtd::net::sockets::tcp_client allows only one client to use a port. More... | |
xtd::net::sockets::network_stream | get_stream () const |
Returns the xtd::net::sockets::network_stream used to send and receive data. More... | |
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 attempt to send all pending data. More... | |
tcp_client & | linger_state (const xtd::net::sockets::linger_option &value) |
Sets a value that specifies whether the xtd::net::sockets::socket will delay closing a socket in an attempt to send all pending data. More... | |
bool | no_delay () const |
Gets a value that disables a delay when send or receive buffers are not full. More... | |
tcp_client & | no_delay (bool value) |
Sets a value that disables a delay when send or receive buffers are not full. More... | |
size_t | receive_buffer_size () const |
Gets the size of the receive buffer. More... | |
tcp_client & | receive_buffer_size (size_t value) |
Sets the size of the receive buffer. More... | |
int32_t | receive_timeout () const |
Gets the amount of time a xtd::net::sockets::tcp_client will wait to receive data once a read operation is initiated. More... | |
tcp_client & | receive_timeout (int32_t value) |
Sets the amount of time a xtd::net::sockets::tcp_client will wait to receive data once a read operation is initiated. More... | |
size_t | send_buffer_size () const |
Gets the size of the send buffer. More... | |
tcp_client & | send_buffer_size (size_t value) |
Sets the size of the send buffer. More... | |
int32_t | send_timeout () const |
Gets the amount of time a xtd::net::sockets::tcp_client will wait for a send operation to complete successfully. More... | |
tcp_client & | send_timeout (int32_t value) |
Gets the amount of time a xtd::net::sockets::tcp_client will wait for a send operation to complete successfully. More... | |
Public Member Functions inherited from xtd::object | |
object ()=default | |
Create a new instance of the ultimate base class object. More... | |
virtual bool | equals (const object &obj) const noexcept |
Determines whether the specified object is equal to the current object. More... | |
virtual size_t | get_hash_code () const noexcept |
Serves as a hash function for a particular type. More... | |
template<typename object_t > | |
std::unique_ptr< object_t > | memberwise_clone () const |
Gets the type of the current instance. More... | |
virtual xtd::ustring | to_string () const noexcept |
Returns a std::string that represents the current object. More... | |
Protected Member Functions | |
bool | active () const noexcept |
Gets a value that indicates whether a connection has been made. More... | |
tcp_client & | active (bool value) noexcept |
Sets a value that indicates whether a connection has been made. More... | |
Additional Inherited Members | |
Static Public Member Functions inherited from xtd::object | |
static bool | equals (const object &object_a, const object &object_b) noexcept |
Determines whether the specified object instances are considered equal. More... | |
static bool | reference_equals (const object &object_a, const object &object_b) noexcept |
Determines whether the specified object instances are the same instance. More... | |
xtd::net::sockets::tcp_client::tcp_client | ( | ) |
Initializes a new instance of the xtd::net::sockets::tcp_client class.
xtd::net::sockets::tcp_client::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 local endpoint.
local_end_point | The xtd::net::ip_end_point to which you bind the TCP xtd::net::sockets::socket. |
xtd::net::sockets::tcp_client::tcp_client | ( | xtd::net::sockets::address_family | address_family | ) |
The xtd::net::sockets::address_family of the IP protocol.
xtd::argument_exception | The family parameter is not equal to xtd::net::sockets::address_family::inter_network -or- The family parameter is not equal to xtd::net::sockets::address_family::inter_network_v6. |
xtd::net::sockets::tcp_client::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 port on the specified host.
hostname | The DNS name of the remote host to which you intend to connect. |
port | The port number of the remote host to which you intend to connect. |
xtd::net::sockets::socket_exception | An error occurred when attempting to access the socket. |
xtd::object_closed_exception | The xtd::net::sockets::socket has been closed. |
|
protectednoexcept |
Gets a value that indicates whether a connection has been made.
|
protectednoexcept |
Sets a value that indicates whether a connection has been made.
value | true if the connection has been made; otherwise, false. |
size_t xtd::net::sockets::tcp_client::available | ( | ) | const |
Gets the amount of data that has been received from the network and is available to be read.
xtd::net::sockets::socket_exception | An error occurred when attempting to access the socket. See the Remarks section for more information. |
xtd::object_closed_exception | The xtd::net::sockets::socket has been closed. |
std::shared_ptr<xtd::iasync_result> xtd::net::sockets::tcp_client::begin_connect | ( | const std::vector< xtd::net::ip_address > & | addresses, |
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::net::ip_address array and a port number (uint16_t).
addresses | At least one xtd::net::ip_address that designates the remote hosts. |
port | The port number of the remote host. |
callback | An xtd::async_callback delegate that references the method to invoke when the operation is complete. |
state | A user-defined object that contains information about the connect operation. This object is passed to the requestCallback delegate when the operation is complete. |
xtd::net::sockets::socket_exception | An error occurred when attempting to access the socket. |
xtd::object_closed_exception | The xtd::net::sockets::socket has been closed. |
std::shared_ptr<xtd::iasync_result> xtd::net::sockets::tcp_client::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::net::ip_address and a port number (uint16_t).
address | The xtd::net::ip_address of the remote host. |
port | The port number of the remote host. |
callback | An xtd::async_callback delegate that references the method to invoke when the operation is complete. |
state | A user-defined object that contains information about the connect operation. This object is passed to the callback delegate when the operation is complete. |
xtd::net::sockets::socket_exception | An error occurred when attempting to access the socket. |
xtd::object_closed_exception | The xtd::net::sockets::socket has been closed. |
std::shared_ptr<xtd::iasync_result> xtd::net::sockets::tcp_client::begin_connect | ( | const xtd::ustring & | host, |
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 a host name (xtd::ustring) and a port number (uint16_t).
host | The name of the remote host. |
port | The port number of the remote host. |
callback | An xtd::async_callback delegate that references the method to invoke when the operation is complete. |
state | A user-defined object that contains information about the connect operation. This object is passed to the requestCallback delegate when the operation is complete. |
xtd::net::sockets::socket_exception | An error occurred when attempting to access the socket. |
xtd::object_closed_exception | The xtd::net::sockets::socket has been closed. |
|
noexcept |
Gets the underlying network xtd::net::sockets::socket.
|
noexcept |
Sets the underlying network xtd::net::sockets::socket.
value | The underlying network xtd::net::sockets::socket |
void xtd::net::sockets::tcp_client::close | ( | ) |
Disposes this xtd::net::sockets::tcp_client instance and requests that the underlying TCP connection be closed.
void xtd::net::sockets::tcp_client::connect | ( | const xtd::net::ip_address & | ip_address, |
uint16_t | port | ||
) |
Connects the client to a remote TCP host using the specified IP address and port number.
ip_address | The xtd::net::ip_address of the remote host to which you intend to send data |
port | The port number to which you intend send data |
xtd::net::sockets::socket_exception | An error occurred when accessing the socket. |
xtd::object_closed_exception | The xtd::net::sockets::socket has been closed. |
void xtd::net::sockets::tcp_client::connect | ( | const xtd::net::ip_end_point & | remote_end_point | ) |
Connects the client to a remote TCP host using the specified remote network endpoint.
remote_end_point | The xtd::net::ip_end_point to which you intend to connect. |
xtd::net::sockets::socket_exception | An error occurred when accessing the socket. |
xtd::object_closed_exception | The xtd::net::sockets::socket has been closed. |
void xtd::net::sockets::tcp_client::connect | ( | const xtd::ustring & | hostname, |
uint16_t | port | ||
) |
Connects the client to the specified port on the specified host.
hostname | The DNS name of the remote host to which you intend to connect. |
port | The port number of the remote host to which you intend to connect. |
xtd::net::sockets::socket_exception | An error occurred when attempting to access the socket. |
xtd::object_closed_exception | The xtd::net::sockets::socket has been closed. |
|
noexcept |
Gets a value indicating whether the underlying xtd::net::sockets::socket for a xtd::net::sockets::tcp_client is connected to a remote host.
void xtd::net::sockets::tcp_client::end_connect | ( | std::shared_ptr< xtd::iasync_result > | async_result | ) |
Ends a pending asynchronous connection attempt.
result | An xtd::iasync_result object returned by a call to xtd::net::sockets::tcp_client::client::begin_connect. |
argument_exception | async_result was not returned by a call to the xtd::net::sockets::socket::begin_connect method. |
xtd::net::sockets::socket_exception | An error occurred when attempting to access the socket. |
xtd::object_closed_exception | The xtd::net::sockets::socket has been closed. |
bool xtd::net::sockets::tcp_client::exclusive_address_use | ( | ) | const |
Gets a bool value that specifies whether the xtd::net::sockets::tcp_client allows only one client to use a port.
xtd::net::sockets::socket_exception | An error occurred when attempting to access the socket. See the Remarks section for more information. |
xtd::object_closed_exception | The xtd::net::sockets::socket has been closed. |
tcp_client& xtd::net::sockets::tcp_client::exclusive_address_use | ( | bool | value | ) |
Sets a bool value that specifies whether the xtd::net::sockets::tcp_client allows only one client to use a port.
value | bool true if the xtd::net::sockets::tcp_client allows only one client to use a specific port; otherwise, false. |
xtd::net::sockets::socket_exception | An error occurred when attempting to access the socket. See the Remarks section for more information. |
xtd::object_closed_exception | The xtd::net::sockets::socket has been closed. |
xtd::net::sockets::network_stream xtd::net::sockets::tcp_client::get_stream | ( | ) | const |
Returns the xtd::net::sockets::network_stream used to send and receive data.
xtd::net::sockets::linger_option xtd::net::sockets::tcp_client::linger_state | ( | ) | const |
Gets a value that specifies whether the xtd::net::sockets::socket will delay closing a socket in an attempt to send all pending data.
xtd::net::sockets::socket_exception | An error occurred when attempting to access the socket. See the Remarks section for more information. |
xtd::object_closed_exception | The xtd::net::sockets::socket has been closed. |
xtd::net::sockets::linger_option::enabled | xtd::net::sockets::linger_option::linger_time | Behavior |
---|---|---|
false (disabled), the default value | The time-out is not applicable, (default). | Attempts to send pending data until the default IP protocol time-out expires. |
true (enabled) | A nonzero time-out | Attempts to send pending data until the specified time-out expires, and if the attempt fails, then Winsock resets the connection. |
true (enabled) | A zero timeout. | Discards any pending data and Winsock resets the connection. |
tcp_client& xtd::net::sockets::tcp_client::linger_state | ( | const xtd::net::sockets::linger_option & | value | ) |
Sets a value that specifies whether the xtd::net::sockets::socket will delay closing a socket in an attempt to send all pending data.
value | A xtd::net::sockets::linger_option that specifies how to linger while closing a socket. |
xtd::net::sockets::socket_exception | An error occurred when attempting to access the socket. See the Remarks section for more information. |
xtd::object_closed_exception | The xtd::net::sockets::socket has been closed. |
xtd::net::sockets::linger_option::enabled | xtd::net::sockets::linger_option::linger_time | Behavior |
---|---|---|
false (disabled), the default value | The time-out is not applicable, (default). | Attempts to send pending data until the default IP protocol time-out expires. |
true (enabled) | A nonzero time-out | Attempts to send pending data until the specified time-out expires, and if the attempt fails, then Winsock resets the connection. |
true (enabled) | A zero timeout. | Discards any pending data and Winsock resets the connection. |
bool xtd::net::sockets::tcp_client::no_delay | ( | ) | const |
Gets a value that disables a delay when send or receive buffers are not full.
xtd::net::sockets::socket_exception | An error occurred when attempting to access the socket. See the Remarks section for more information. |
xtd::object_closed_exception | The xtd::net::sockets::socket has been closed. |
tcp_client& xtd::net::sockets::tcp_client::no_delay | ( | bool | value | ) |
Sets a value that disables a delay when send or receive buffers are not full.
value | true if the delay is disabled; otherwise, false. The default value is false. |
xtd::net::sockets::socket_exception | An error occurred when attempting to access the socket. See the Remarks section for more information. |
xtd::object_closed_exception | The xtd::net::sockets::socket has been closed. |
size_t xtd::net::sockets::tcp_client::receive_buffer_size | ( | ) | const |
Gets the size of the receive buffer.
xtd::net::sockets::socket_exception | An error occurred when attempting to access the socket. See the Remarks section for more information. |
xtd::object_closed_exception | The xtd::net::sockets::socket has been closed. |
tcp_client& xtd::net::sockets::tcp_client::receive_buffer_size | ( | size_t | value | ) |
Sets the size of the receive buffer.
value | A size_t that contains the size, in bytes, of the receive buffer. The default is 8192. |
xtd::net::sockets::socket_exception | An error occurred when attempting to access the socket. See the Remarks section for more information. |
xtd::object_closed_exception | The xtd::net::sockets::socket has been closed. |
int32_t xtd::net::sockets::tcp_client::receive_timeout | ( | ) | const |
Gets the amount of time a xtd::net::sockets::tcp_client will wait to receive data once a read operation is initiated.
tcp_client& xtd::net::sockets::tcp_client::receive_timeout | ( | int32_t | value | ) |
Sets the amount of time a xtd::net::sockets::tcp_client will wait to receive data once a read operation is initiated.
value | The time-out value of the connection in milliseconds. The default value is 0. |
size_t xtd::net::sockets::tcp_client::send_buffer_size | ( | ) | const |
Gets the size of the send buffer.
tcp_client& xtd::net::sockets::tcp_client::send_buffer_size | ( | size_t | value | ) |
Sets the size of the send buffer.
value | The size of the send buffer, in bytes. The default value is 8192 bytes. |
int32_t xtd::net::sockets::tcp_client::send_timeout | ( | ) | const |
Gets the amount of time a xtd::net::sockets::tcp_client will wait for a send operation to complete successfully.
tcp_client& xtd::net::sockets::tcp_client::send_timeout | ( | int32_t | value | ) |
Gets the amount of time a xtd::net::sockets::tcp_client will wait for a send operation to complete successfully.
value | The send time-out value, in milliseconds. The default value is 0. |