xtd 0.2.0
Loading...
Searching...
No Matches
xtd::net::sockets::socket Class Reference
Inheritance diagram for xtd::net::sockets::socket:
xtd::object xtd::iequatable< socket > xtd::interface xtd::equality_operators< type_t, equatable_t >

Definition

Implements the Berkeley sockets interface.

Implements the Berkeley sockets interface.
Definition socket.h:74
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.h:42
#define core_export_
Define shared library export.
Definition core_export.h:13
Inheritance
xtd::objectxtd::net::sockets::socket
Header
#include <xtd/net/sockets/socket>
Namespace
xtd::net::sockets
Library
xtd.core
Remarks
The xtd::net::sockets::socket class provides a rich set of methods and properties for network communications. The xtd::net::sockets::socket class allows you to perform both synchronous and asynchronous data transfer using any of the communication protocols listed in the xtd::net::sockets::protocol_type enumeration.
The xtd::net::sockets::socket class follows the xtd naming pattern for asynchronous methods. For example, the synchronous xtd::net::sockets::receive method corresponds to the asynchronous xtd::net::sockets::begin_receive and xtd::net::sockets::end_receive methods.
If your application only requires one thread during execution, use the following methods, which are designed for synchronous operation mode.
To process communications using separate threads during execution, use the following methods, which are designed for asynchronous operation mode.
If you perform multiple asynchronous operations on a socket, they do not necessarily complete in the order in which they are started.
When you are finished sending and receiving data, use the xtd::net::sockets::socket::shutdown method to disable the xtd::net::sockets::socket. After calling xtd::net::sockets::socket::shutdown, call the xtd::net::sockets::socket::close method to release all resources associated with the xtd::net::sockets::socket.
The xtd::net::sockets::socket class allows you to configure your xtd::net::sockets::socket using the xtd::net::sockets::socket::set_socket_option method. Retrieve these settings using the xtd::net::sockets::socket::get_socket_option method.
Note
If you are writing a relatively simple application and do not require maximum performance, consider using xtd::net::sockets::tcp_client, xtd::net::sockets::tcp_listener, and xtd::net::sockets::udp_client. These classes provide a simpler and more user-friendly interface to xtd::net::sockets::socket communications.
Examples
network_stream.cpp, socket_tcp_ip_v4.cpp, socket_tcp_ip_v4_without_thread.cpp, socket_tcp_ip_v6.cpp, socket_udp_ip_v4.cpp, and socket_udp_ip_v6.cpp.

Public Constructors

 socket ()
 Initializes a new instance of the xtd::net::sockets::socket class.
 
 socket (intptr handle)
 Initializes a new instance of the xtd::net::sockets::socket class for the specified socket handle.
 
 socket (const xtd::net::sockets::socket_information &socket_information)
 Initializes a new instance of the xtd::net::sockets::socket class using the specified value returned from xtd::net::sockets::socket::duplicate_and_close.
 
 socket (xtd::net::sockets::socket_type socket_type, xtd::net::sockets::protocol_type protocol_type)
 Initializes a new instance of the xtd::net::sockets::socket class using the specified socket type and protocol. If the operating system supports IPv6, this constructor creates a dual-mode socket; otherwise, it creates an IPv4 socket.
 
 socket (xtd::net::sockets::address_family address_family, xtd::net::sockets::socket_type socket_type, xtd::net::sockets::protocol_type protocol_type)
 Initializes a new instance of the xtd::net::sockets::socket class using the specified address family, socket type and protocol.
 

Public Properties

xtd::net::sockets::address_family address_family () const noexcept
 Gets the address family of the xtd::net::sockets::socket.
 
size_t available () const
 Gets the amount of data that has been received from the network and is available to be read.
 
bool blocking () const
 Gets a value that indicates whether the xtd::net::sockets::socket is in blocking mode.
 
socketblocking (bool value)
 Sets a value that indicates whether the xtd::net::sockets::socket is in blocking mode.
 
bool connected () const noexcept
 Gets a value that indicates whether a xtd::net::sockets::socket is connected to a remote host as of the last xtd::net::sockets::socket::send or xtd::net::sockets::socket::receive operation.
 
bool dont_fragment () const
 Gets a value that specifies whether the xtd::net::sockets::socket allows Internet Protocol (IP) datagrams to be fragmented.
 
socketdont_fragment (bool value)
 Sets a value that specifies whether the xtd::net::sockets::socket allows Internet Protocol (IP) datagrams to be fragmented.
 
bool dual_mode () const
 Gets a value that specifies whether the xtd::net::sockets::socket is a dual-mode socket used for both IPv4 and IPv6.
 
socketdual_mode (bool value)
 Sets a value that specifies whether the xtd::net::sockets::socket is a dual-mode socket used for both IPv4 and IPv6.
 
bool enable_broadcast () const
 Gets a boolean value that specifies whether the xtd::net::sockets::socket can send or receive broadcast packets.
 
socketenable_broadcast (bool value)
 Sets a bool value that specifies whether the xtd::net::sockets::socket can send or receive broadcast packets.
 
bool exclusive_address_use () const
 Gets a boolean value that specifies whether the xtd::net::sockets::socket allows only one process to bind to a port.
 
socketexclusive_address_use (bool value)
 Gets a boolean value that specifies whether the xtd::net::sockets::socket allows only one process to bind to a port.
 
intptr handle () const noexcept
 Gets the operating system handle for the xtd::net::sockets::socket.
 
bool is_bound () const noexcept
 Gets a value that indicates whether the xtd::net::sockets::socket is bound to a specific local port.
 
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.
 
socketlinger_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.
 
xtd::sptr< xtd::net::end_pointlocal_end_point () const
 Gets the local endpoint.
 
bool multicast_loopback () const
 Gets a value that specifies whether outgoing multicast packets are delivered to the sending application.
 
socketmulticast_loopback (bool value)
 Sets a value that specifies whether outgoing multicast packets are delivered to the sending application.
 
bool no_delay () const
 Gets a boolean value that specifies whether the stream xtd::net::sockets::socket is using the Nagle algorithm.
 
socketno_delay (bool value)
 Gets a boolean value that specifies whether the stream xtd::net::sockets::socket is using the Nagle algorithm.
 
xtd::net::sockets::protocol_type protocol_type () const noexcept
 Gets the protocol type of the xtd::net::sockets::socket.
 
size_t receive_buffer_size () const
 Gets a value that specifies the size of the receive buffer of the xtd::net::sockets::socket.
 
socketreceive_buffer_size (size_t value)
 Sets a value that specifies the size of the receive buffer of the xtd::net::sockets::socket.
 
int32 receive_timeout () const
 Gets a value that specifies the amount of time after which a synchronous xtd::net::sockets::socket::receive call will time out.
 
socketreceive_timeout (int32 value)
 Sets a value that specifies the amount of time after which a synchronous xtd::net::sockets::socket::receive call will time out.
 
xtd::sptr< xtd::net::end_pointremote_end_point () const
 Gets the remote endpoint.
 
size_t send_buffer_size () const
 Gets a value that specifies the size of the send buffer of the xtd::net::sockets::socket.
 
socketsend_buffer_size (size_t value)
 Sets a value that specifies the size of the send buffer of the xtd::net::sockets::socket.
 
int32 send_timeout () const
 Gets a value that specifies the amount of time after which a synchronous xtd::net::sockets::socket::send call will time out.
 
socketsend_timeout (int32 value)
 Sets a value that specifies the amount of time after which a synchronous xtd::net::sockets::socket::send call will time out.
 
xtd::net::sockets::socket_type socket_type () const noexcept
 Gets the type of the xtd::net::sockets::socket.
 
xtd::byte ttl () const
 Gets a value that specifies the Time To Live (TTL) value of Internet Protocol (IP) packets sent by the xtd::net::sockets::socket.
 
socketttl (xtd::byte value)
 Sets a value that specifies the Time To Live (TTL) value of Internet Protocol (IP) packets sent by the xtd::net::sockets::socket.
 

Public Methods

socket accept ()
 Creates a new xtd::net::sockets::socket for a newly created connection.
 
bool accept_async (xtd::net::sockets::socket_async_event_args &e)
 Begins an asynchronous operation to accept an incoming connection attempt.
 
xtd::sptr< xtd::iasync_resultbegin_accept (xtd::async_callback callback, const std::any &state)
 Begins an asynchronous operation to accept an incoming connection attempt.
 
template<typename end_point_t >
xtd::sptr< xtd::iasync_resultbegin_connect (const end_point_t &remote_end_point, xtd::async_callback callback, const std::any &state)
 Begins an asynchronous request for a remote host connection.
 
xtd::sptr< xtd::iasync_resultbegin_connect (const xtd::net::ip_address &address, uint16 port, xtd::async_callback callback, const std::any &state)
 Begins an asynchronous request for a remote host connection. The host is specified by an xtd::net::ip_address and a port number.
 
xtd::sptr< xtd::iasync_resultbegin_connect (const std::vector< xtd::net::ip_address > &addresses, uint16 port, xtd::async_callback callback, const std::any &state)
 Begins an asynchronous request for a remote host connection. The host is specified by an xtd::net::ip_address array and a port number.
 
xtd::sptr< xtd::iasync_resultbegin_connect (const xtd::string &host, uint16 port, xtd::async_callback callback, const std::any &state)
 Begins an asynchronous request for a remote host connection. The host is specified by a host name and a port number.
 
xtd::sptr< xtd::iasync_resultbegin_disconnect (bool reuse_socket, xtd::async_callback callback, const std::any &state)
 Begins an asynchronous request to disconnect from a remote endpoint.
 
xtd::sptr< xtd::iasync_resultbegin_receive (std::vector< xtd::byte > &buffer, size_t offset, size_t size, xtd::net::sockets::socket_flags socket_flags, xtd::async_callback callback, const std::any &state)
 Begins to asynchronously receive data from a connected xtd::net::sockets::socket::socket.
 
xtd::sptr< xtd::iasync_resultbegin_receive (std::vector< xtd::byte > &buffer, size_t offset, size_t size, xtd::net::sockets::socket_flags socket_flags, xtd::net::sockets::socket_error &error_code, xtd::async_callback callback, const std::any &state)
 Begins to asynchronously receive data from a connected xtd::net::sockets::socket::socket.
 
xtd::sptr< xtd::iasync_resultbegin_receive_from (std::vector< xtd::byte > &buffer, size_t offset, size_t size, xtd::net::sockets::socket_flags socket_flags, xtd::net::end_point &remote_end_point, xtd::async_callback callback, const std::any &state)
 Begins to asynchronously receive data from a specified network device.
 
xtd::sptr< xtd::iasync_resultbegin_receive_message_from (std::vector< xtd::byte > &buffer, size_t offset, size_t size, xtd::net::sockets::socket_flags socket_flags, xtd::net::end_point &remote_end_point, xtd::async_callback callback, const std::any &state)
 Begins to asynchronously receive the specified number of bytes of data into the specified location of the data buffer, using the specified xtd::net::sockets::socket_flags, and stores the endpoint and packet information.
 
xtd::sptr< xtd::iasync_resultbegin_send (const std::vector< xtd::byte > &buffer, size_t offset, size_t size, xtd::net::sockets::socket_flags socket_flags, xtd::async_callback callback, const std::any &state)
 Sends data asynchronously to a connected xtd::net::sockets::socket::socket.
 
xtd::sptr< xtd::iasync_resultbegin_send (const std::vector< xtd::byte > &buffer, size_t offset, size_t size, xtd::net::sockets::socket_flags socket_flags, xtd::net::sockets::socket_error &error_code, xtd::async_callback callback, const std::any &state)
 Sends data asynchronously to a connected xtd::net::sockets::socket::socket.
 
xtd::sptr< xtd::iasync_resultbegin_send_to (const std::vector< xtd::byte > &buffer, size_t offset, size_t size, xtd::net::sockets::socket_flags socket_flags, const xtd::net::end_point &remote_end_point, xtd::async_callback callback, const std::any &state)
 Sends data asynchronously to a specific remote host.
 
template<typename end_point_t >
void bind (const end_point_t &local_end_point)
 Associates a xtd::net::sockets::socket with a local endpoint.
 
void close ()
 Closes the xtd::net::sockets::socket connection and releases all associated resources.
 
template<typename end_point_t >
void connect (const end_point_t &remote_end_point)
 Establishes a connection to a remote host.
 
void connect (const xtd::net::ip_address &address, uint16 port)
 Establishes a connection to a remote host. The host is specified by an IP address and a port number.
 
void connect (const std::vector< xtd::net::ip_address > &addresses, uint16 port)
 Establishes a connection to a remote host. The host is specified by an array of IP addresses and a port number.
 
void connect (const xtd::string &host, uint16 port)
 Establishes a connection to a remote host. The host is specified by a host name and a port number.
 
void disconnect (bool reuse_socket)
 Closes the socket connection and allows reuse of the socket.
 
socket end_accept (xtd::sptr< xtd::iasync_result > async_result)
 Asynchronously accepts an incoming connection attempt and creates a new xtd::net::sockets::socket::socket to handle remote host communication.
 
void end_connect (xtd::sptr< xtd::iasync_result > async_result)
 Ends a pending asynchronous connection request.
 
void end_disconnect (xtd::sptr< xtd::iasync_result > async_result)
 Ends a pending asynchronous disconnect request.
 
size_t end_receive (xtd::sptr< xtd::iasync_result > async_result)
 Ends a pending asynchronous read.
 
size_t end_receive (xtd::sptr< xtd::iasync_result > async_result, xtd::net::sockets::socket_error &error_code)
 Ends a pending asynchronous read.
 
size_t end_receive_from (xtd::sptr< xtd::iasync_result > async_result, xtd::sptr< xtd::net::end_point > &end_point)
 Ends a pending asynchronous read from a specific endpoint.
 
size_t end_receive_message_from (xtd::sptr< xtd::iasync_result > async_result, xtd::net::sockets::socket_flags &socket_flags, xtd::sptr< xtd::net::end_point > &end_point, xtd::net::sockets::ip_packet_information &ip_packet_information)
 Ends a pending asynchronous read from a specific endpoint. This method also reveals more information about the packet than xtd::net::sockets::socket::end_receive_from(xtd::iasync_result, xtd::net::end_point).
 
size_t end_send (xtd::sptr< xtd::iasync_result > async_result)
 Ends a pending asynchronous send.
 
size_t end_send (xtd::sptr< xtd::iasync_result > async_result, xtd::net::sockets::socket_error &error_code)
 Ends a pending asynchronous send.
 
size_t end_send_to (xtd::sptr< xtd::iasync_result > async_result)
 Ends a pending asynchronous send to a specific location.
 
bool equals (const socket &s) const noexcept override
 
size_t get_raw_socket_option (int32 socket_option_level, int32 socket_option_name, intptr option_value, size_t size_option_value) const
 Gets a socket option value using platform-specific level and name identifiers.
 
int32 get_socket_option (xtd::net::sockets::socket_option_level socket_option_level, xtd::net::sockets::socket_option_name socket_option_name) const
 Returns the value of a specified xtd::net::sockets::socket option, represented as integer.
 
xtd::net::sockets::linger_option get_socket_linger_option () const
 Returns the linger xtd::net::sockets::socket option, represented as xtd::net::sockets::linger_option.
 
xtd::net::sockets::multicast_option get_socket_multicast_option (xtd::net::sockets::socket_option_name socket_option_name) const
 Returns the multicast xtd::net::sockets::socket option, represented as xtd::net::sockets::multicast_option.
 
xtd::net::sockets::ip_v6_multicast_option get_socket_ip_v6_multicast_option (xtd::net::sockets::socket_option_name socket_option_name) const
 Returns the multicast xtd::net::sockets::socket option, represented as xtd::net::sockets::ip_v6_multicast_option.
 
size_t io_control (int32 io_control_code, std::vector< xtd::byte > &option_in_value, std::vector< xtd::byte > &option_out_value)
 Sets low-level operating modes for the xtd::net::sockets::socket using numerical control codes.
 
size_t io_control (xtd::net::sockets::io_control_code io_control_code, std::vector< xtd::byte > &option_in_value, std::vector< xtd::byte > &option_out_value)
 Sets low-level operating modes for the xtd::net::sockets::socket using xtd::net::sockets::io_control_code control codes.
 
void listen (size_t backlog)
 Places a xtd::net::sockets::socket in a listening state.
 
void listen ()
 Places a xtd::net::sockets::socket in a listening state.
 
bool poll (int32 micro_seconds, xtd::net::sockets::select_mode mode)
 Determines the status of the xtd::net::sockets::socket.
 
size_t receive (std::vector< xtd::byte > &buffer)
 Receives data from a bound xtd::net::sockets::socket into a receive buffer.
 
size_t receive (std::vector< xtd::byte > &buffer, xtd::net::sockets::socket_flags socket_flags)
 Receives data from a bound xtd::net::sockets::socket into a receive buffer, using the specified xtd::net::sockets::socket_flags.
 
size_t receive (std::vector< xtd::byte > &buffer, size_t size, xtd::net::sockets::socket_flags socket_flags)
 Receives the specified number of bytes of data from a bound xtd::net::sockets::socket into a receive buffer, using the specified xtd::net::sockets::socket_flags.
 
size_t receive (std::vector< xtd::byte > &buffer, size_t offset, size_t size, xtd::net::sockets::socket_flags socket_flags)
 Receives the specified number of bytes from a bound xtd::net::sockets::socket into the specified offset position of the receive buffer, using the specified xtd::net::sockets::socket_flags.
 
size_t receive (std::vector< xtd::byte > &buffer, size_t offset, size_t size, xtd::net::sockets::socket_flags socket_flags, xtd::net::sockets::socket_error &error)
 Receives the specified number of bytes from a bound xtd::net::sockets::socket into the specified offset position of the receive buffer, using the specified xtd::net::sockets::socket_flags.
 
size_t receive_from (std::vector< xtd::byte > &buffer, xtd::net::end_point &remote_end_point)
 Receives data from a bound xtd::net::sockets::socket into a receive buffer.
 
size_t receive_from (std::vector< xtd::byte > &buffer, xtd::net::sockets::socket_flags socket_flags, xtd::net::end_point &remote_end_point)
 Receives data from a bound xtd::net::sockets::socket into a receive buffer.
 
size_t receive_from (std::vector< xtd::byte > &buffer, size_t size, xtd::net::sockets::socket_flags socket_flags, xtd::net::end_point &remote_end_point)
 Receives data from a bound xtd::net::sockets::socket into a receive buffer.
 
size_t receive_from (std::vector< xtd::byte > &buffer, size_t offset, size_t size, xtd::net::sockets::socket_flags socket_flags, xtd::net::end_point &remote_end_point)
 Receives data from a bound xtd::net::sockets::socket into a receive buffer.
 
size_t receive_message_from (std::vector< xtd::byte > &buffer, size_t offset, size_t size, xtd::net::sockets::socket_flags socket_flags, xtd::net::end_point &remote_end_point, xtd::net::sockets::ip_packet_information &ip_packet_information)
 
size_t send (const std::vector< xtd::byte > &buffer)
 Sends data to a connected xtd::net::sockets::socket.
 
size_t send (const std::vector< xtd::byte > &buffer, xtd::net::sockets::socket_flags socket_flags)
 Sends data to a connected xtd::net::sockets::socket using the specified xtd::net::sockets::socket_flags.
 
size_t send (const std::vector< xtd::byte > &buffer, size_t size, xtd::net::sockets::socket_flags socket_flags)
 Sends the specified number of bytes of data to a connected xtd::net::sockets::socket, using the specified xtd::net::sockets::socket_flags.
 
size_t send (const std::vector< xtd::byte > &buffer, size_t offset, size_t size, xtd::net::sockets::socket_flags socket_flags)
 Sends the specified number of bytes of data to a connected xtd::net::sockets::socket, starting at the specified offset, and using the specified xtd::net::sockets::socket_flags.
 
size_t send (const std::vector< xtd::byte > &buffer, size_t offset, size_t size, xtd::net::sockets::socket_flags socket_flags, xtd::net::sockets::socket_error &error_code)
 Sends the specified number of bytes of data to a connected xtd::net::sockets::socket, starting at the specified offset, and using the specified xtd::net::sockets::socket_flags.
 
size_t send_to (const std::vector< xtd::byte > &buffer, const xtd::net::end_point &remote_end_point)
 Sends data to the specified endpoint.
 
size_t send_to (const std::vector< xtd::byte > &buffer, xtd::net::sockets::socket_flags socket_flags, const xtd::net::end_point &remote_end_point)
 Sends data to a specific endpoint using the specified xtd::net::sockets::socket_flags.
 
size_t send_to (const std::vector< xtd::byte > &buffer, size_t size, xtd::net::sockets::socket_flags socket_flags, const xtd::net::end_point &remote_end_point)
 Sends the specified number of bytes of data to the specified endpoint using the specified xtd::net::sockets::socket_flags.
 
size_t send_to (const std::vector< xtd::byte > &buffer, size_t offset, size_t size, xtd::net::sockets::socket_flags socket_flags, const xtd::net::end_point &remote_end_point)
 Sends the specified number of bytes of data to the specified endpoint, starting at the specified location in the buffer, and using the specified xtd::net::sockets::socket_flags.
 
void set_ip_protection_level (xtd::net::sockets::ip_protection_level level)
 Sets the IP protection level on a socket.
 
void set_socket_option (xtd::net::sockets::socket_option_level socket_option_level, xtd::net::sockets::socket_option_name socket_option_name, bool option_value)
 Sets the specified xtd::net::sockets::socket option to the specified integer value.
 
void set_socket_option (xtd::net::sockets::socket_option_level socket_option_level, xtd::net::sockets::socket_option_name socket_option_name, int32 option_value)
 Sets the specified xtd::net::sockets::socket option to the specified integer value.
 
void set_socket_option (xtd::net::sockets::linger_option option_value)
 Sets the linger xtd::net::sockets::socket option to the specified integer value.
 
void set_socket_option (xtd::net::sockets::socket_option_name socket_option_name, const xtd::net::sockets::multicast_option &option_value)
 Sets the linger xtd::net::sockets::socket option to the specified integer value.
 
void set_socket_option (xtd::net::sockets::socket_option_name socket_option_name, const xtd::net::sockets::ip_v6_multicast_option &option_value)
 Sets the linger xtd::net::sockets::socket option to the specified integer value.
 
void set_raw_socket_option (int32 socket_option_level, int32 socket_option_name, intptr option_value, size_t option_value_size)
 Sets a socket option value using platform-specific level and name identifiers.
 
void shutdown (xtd::net::sockets::socket_shutdown how)
 Disables sends and receives on a xtd::net::sockets::socket.
 
virtual bool equals (const object &obj) const noexcept
 Determines whether the specified object is equal to the current object.
 
template<typename object_a_t , typename object_b_t >
static bool equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are considered equal.
 

Public Static Properties

static bool os_supports_ip_v4 () noexcept
 Indicates whether the underlying operating system and network adaptors support Internet Protocol version 4 (IPv4).
 
static bool os_supports_ip_v6 () noexcept
 Indicates whether the underlying operating system and network adaptors support Internet Protocol version 6 (IPv6).
 

Public Static Methods

static size_t select (std::vector< socket > &check_read, std::vector< socket > &check_write, std::vector< socket > &check_error, int32 microseconds)
 Determines the status of one or more sockets.
 

Additional Inherited Members

- Public Member Functions inherited from xtd::object
 object ()=default
 Create a new instance of the ultimate base class object.
 
virtual size_t get_hash_code () const noexcept
 Serves as a hash function for a particular type.
 
virtual type_object get_type () const noexcept
 Gets the type of the current instance.
 
template<typename object_t >
xtd::uptr< object_t > memberwise_clone () const
 Creates a shallow copy of the current object.
 
virtual xtd::string to_string () const noexcept
 Returns a xtd::string that represents the current object.
 
- Public Member Functions inherited from xtd::iequatable< socket >
virtual bool equals (const socket &) const noexcept=0
 Indicates whether the current object is equal to another object of the same type.
 
- Static Public Member Functions inherited from xtd::object
template<typename object_a_t , typename object_b_t >
static bool equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are considered equal.
 
template<typename object_a_t , typename object_b_t >
static bool reference_equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are the same instance.
 

Constructor & Destructor Documentation

◆ socket() [1/5]

xtd::net::sockets::socket::socket ( )

Initializes a new instance of the xtd::net::sockets::socket class.

◆ socket() [2/5]

xtd::net::sockets::socket::socket ( intptr  handle)
explicit

Initializes a new instance of the xtd::net::sockets::socket class for the specified socket handle.

Parameters
handleThe socket handle for the socket that the xtd::net::sockets::socket object will encapsulate.
Exceptions
xtd::argument_exceptionThe handle is invalid.
Remarks
This method populates the xtd::net::sockets::socket instance with data gathered from the supplied intptr. Different operating systems provide varying levels of support for querying a socket handle or file descriptor for its properties and configuration. Some of the public APIs on the resulting xtd::net::sockets::socket instance may differ based on operating system, such as xtd::net::sockets::socket::protocol_type and xtd::net::sockets::socket::blocking.

◆ socket() [3/5]

xtd::net::sockets::socket::socket ( const xtd::net::sockets::socket_information socket_information)
explicit

Initializes a new instance of the xtd::net::sockets::socket class using the specified value returned from xtd::net::sockets::socket::duplicate_and_close.

Parameters
socket_informationThe socket information returned by xtd::net::sockets::socket::duplicate_and_close.
Remarks
If you call the xtd::net::sockets::socket constructor multiple times with the same byte array as the argument for each call, you will create multiple xtd::net::sockets::socket with the same underlying socket. This practice is strongly discouraged.

◆ socket() [4/5]

xtd::net::sockets::socket::socket ( xtd::net::sockets::socket_type  socket_type,
xtd::net::sockets::protocol_type  protocol_type 
)

Initializes a new instance of the xtd::net::sockets::socket class using the specified socket type and protocol. If the operating system supports IPv6, this constructor creates a dual-mode socket; otherwise, it creates an IPv4 socket.

Parameters
socket_typeOne of the xtd::net::sockets::socket_type values.
protocol_typeOne of the xtd::net::sockets::protocol_type values.
Exceptions
xtd::net:sockets::socket_exceptionThe combination of socket_type and protocol_type results in an invalid socket.
Remarks
The socket_type parameter specifies the type of the xtd::net::sockets::socket class and the protocol_type parameter specifies the protocol used by xtd::net::sockets::socket. The two parameters are not independent. Often the xtd::net::sockets::socket type is implicit in the protocol. If the combination of xtd::net::sockets::socket type and protocol type results in an invalid xtd::net::sockets::socket, this constructor throws a xtd::net::sockets::socket_exception.
Note
If this constructor throws a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation for a detailed description of the error.

◆ socket() [5/5]

xtd::net::sockets::socket::socket ( xtd::net::sockets::address_family  address_family,
xtd::net::sockets::socket_type  socket_type,
xtd::net::sockets::protocol_type  protocol_type 
)

Initializes a new instance of the xtd::net::sockets::socket class using the specified address family, socket type and protocol.

Parameters
address_familyOne of the xtd::net::sockets::address_family values.
socket_typeOne of the xtd::net::sockets::socket_type values.
protocol_typeOne of the xtd::net::sockets::protocol_type values.
Exceptions
xtd::net:sockets::socket_exceptionThe combination of address_family, socket_type and protocol_type results in an invalid socket.
Remarks
The address_family parameter specifies the addressing scheme that the xtd::net::sockets::socket class uses, the socket_type parameter specifies the type of the xtd::net::sockets::socket class, and the protocol_type parameter specifies the protocol used by xtd::net::sockets::socket. The three parameters are not independent. Some address families restrict which protocols can be used with them, and often the xtd::net::sockets::socket type is implicit in the protocol. If the combination of address family, xtd::net::sockets::socket type, and protocol type results in an invalid xtd::net::sockets::socket, this constructor throws a xtd::net::sockets::socket_exception.
Note
If this constructor throws a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation for a detailed description of the error.

Member Function Documentation

◆ address_family()

xtd::net::sockets::address_family xtd::net::sockets::socket::address_family ( ) const
noexcept

Gets the address family of the xtd::net::sockets::socket.

Returns
One of the xtd::net::sockets::address_family values.
Remarks
The xtd::net::sockets::address_family specifies the addressing scheme that an instance of the xtd::net::sockets::socket class can use. This property is read-only and is set when the xtd::net::sockets::socket is created.

◆ available()

size_t xtd::net::sockets::socket::available ( ) const

Gets the amount of data that has been received from the network and is available to be read.

Returns
The number of bytes of data received from the network and available to be read.
Exceptions
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.

◆ blocking() [1/2]

bool xtd::net::sockets::socket::blocking ( ) const

Gets a value that indicates whether the xtd::net::sockets::socket is in blocking mode.

Returns
true if the xtd::net::sockets::socket will block; otherwise, false. The default is true.
Exceptions
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
The xtd::net::sockets::socket::blocking property indicates whether a xtd::net::sockets::socket is in blocking mode.
If you are in blocking mode, and you make a method call which does not complete immediately, your application will block execution until the requested operation completes. If you want execution to continue even though the requested operation is not complete, change the xtd::net::sockets::socket::blocking property to false. The xtd::net::sockets::socket::blocking property has no effect on asynchronous methods. If you are sending and receiving data asynchronously and want to block execution, use the xtd::threading::manual_reset_event class.
Note
If you receive a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation for a detailed description of the error.

◆ blocking() [2/2]

socket & xtd::net::sockets::socket::blocking ( bool  value)

Sets a value that indicates whether the xtd::net::sockets::socket is in blocking mode.

Parameters
valuetrue if the xtd::net::sockets::socket will block; otherwise, false. The default is true.
Returns
This current instance.
Exceptions
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
The xtd::net::sockets::socket::blocking property indicates whether a xtd::net::sockets::socket is in blocking mode.
If you are in blocking mode, and you make a method call which does not complete immediately, your application will block execution until the requested operation completes. If you want execution to continue even though the requested operation is not complete, change the xtd::net::sockets::socket::blocking property to false. The xtd::net::sockets::socket::blocking property has no effect on asynchronous methods. If you are sending and receiving data asynchronously and want to block execution, use the xtd::threading::manual_reset_event class.
Note
If you receive a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation for a detailed description of the error.

◆ connected()

bool xtd::net::sockets::socket::connected ( ) const
noexcept

Gets a value that indicates whether a xtd::net::sockets::socket is connected to a remote host as of the last xtd::net::sockets::socket::send or xtd::net::sockets::socket::receive operation.

Returns
true if the xtd::net::sockets::socket was connected to a remote resource as of the most recent operation; otherwise, false.
Remarks
The xtd::net::sockets::socket::connected property gets the connection state of the xtd::net::sockets::socket as of the last I/O operation. When it returns false, the xtd::net::sockets::socket was either never connected, or is no longer connected. xtd::net::sockets::socket::connected is not thread-safe; it may return true after an operation is aborted when the xtd::net::sockets::socket is disconnected from another thread.
The value of the xtd::net::sockets::socket::connected property reflects the state of the connection as of the most recent operation. If you need to determine the current state of the connection, make a nonblocking, zero-byte xtd::net::sockets::socket::send call. If the call returns successfully or throws a WAEWOULDBLOCK error code (10035), then the socket is still connected; otherwise, the socket is no longer connected.
If you call xtd::net::sockets::socket::connect on a User Datagram Protocol (UDP) socket, the xtd::net::sockets::socket::connected property always returns true; however, this action does not change the inherent connectionless nature of UDP.

◆ dont_fragment() [1/2]

bool xtd::net::sockets::socket::dont_fragment ( ) const

Gets a value that specifies whether the xtd::net::sockets::socket allows Internet Protocol (IP) datagrams to be fragmented.

Returns
true if the xtd::net::sockets::socket doesn't allow datagram fragmentation; otherwise, false. The default is true.
Exceptions
xtd::not_supported_exceptionThe socket is not in the xtd::net::sockets::address_family::inter_network family.
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ dont_fragment() [2/2]

socket & xtd::net::sockets::socket::dont_fragment ( bool  value)

Sets a value that specifies whether the xtd::net::sockets::socket allows Internet Protocol (IP) datagrams to be fragmented.

Parameters
valuetrue if the xtd::net::sockets::socket doesn't allow datagram fragmentation; otherwise, false. The default is true.
Returns
This current instance.
Exceptions
xtd::not_supported_exceptionThe socket is not in the xtd::net::sockets::address_family::inter_network family.
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ dual_mode() [1/2]

bool xtd::net::sockets::socket::dual_mode ( ) const

Gets a value that specifies whether the xtd::net::sockets::socket is a dual-mode socket used for both IPv4 and IPv6.

Returns
true if the xtd::net::sockets::socket is a dual-mode socket; otherwise, false. The default is true if the socket was created by calling the xtd::net::sockets::socket(xtd::net::sockets::socket_type, xtd::net::sockets::protocol_type) constructor and the operating system supports IPv6; otherwise, the default is false.
Exceptions
xtd::not_supported_exceptionThe socket is not in the xtd::net::sockets::address_family::inter_network_v6 family.
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ dual_mode() [2/2]

socket & xtd::net::sockets::socket::dual_mode ( bool  value)

Sets a value that specifies whether the xtd::net::sockets::socket is a dual-mode socket used for both IPv4 and IPv6.

Parameters
valuetrue if the xtd::net::sockets::socket is a dual-mode socket; otherwise, false. The default is true if the socket was created by calling the xtd::net::sockets::socket(xtd::net::sockets::socket_type, xtd::net::sockets::protocol_type) constructor and the operating system supports IPv6; otherwise, the default is false.
Returns
This current instance.
Exceptions
xtd::not_supported_exceptionThe socket is not in the xtd::net::sockets::address_family::inter_network_v6 family.
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ enable_broadcast() [1/2]

bool xtd::net::sockets::socket::enable_broadcast ( ) const

Gets a boolean value that specifies whether the xtd::net::sockets::socket can send or receive broadcast packets.

Returns
true if the xtd::net::sockets::socket allows broadcast packets; otherwise, false. The default is false.
Exceptions
xtd::net::sockets::socket_exceptionThis option is valid for a datagram socket only.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
Broadcasting is limited to a specific subnet, and must use User Datagram Protocol (UDP.) For Internet Protocol version 4, you can broadcast to your local subnet by sending a packet to 255.255.255.255; or you can use the directed broadcast address, which is the network portion of an Internet Protocol (IP) address with all bits set in the host portion. For example, if your IP address is 192.168.1.40 (a Class C address, with a netmask of 255.255.255.0 – the network portion is the first three octets, and the host portion is the last octet), your directed broadcast address is 192.168.1.255.
Setting this property on a Transmission Control Protocol (TCP) socket will have no effect.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ enable_broadcast() [2/2]

socket & xtd::net::sockets::socket::enable_broadcast ( bool  value)

Sets a bool value that specifies whether the xtd::net::sockets::socket can send or receive broadcast packets.

Parameters
valuetrue if the xtd::net::sockets::socket allows broadcast packets; otherwise, false. The default is false.
Returns
This current instance.
Exceptions
xtd::net::sockets::socket_exceptionThis option is valid for a datagram socket only.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
Broadcasting is limited to a specific subnet, and must use User Datagram Protocol (UDP.) For Internet Protocol version 4, you can broadcast to your local subnet by sending a packet to 255.255.255.255; or you can use the directed broadcast address, which is the network portion of an Internet Protocol (IP) address with all bits set in the host portion. For example, if your IP address is 192.168.1.40 (a Class C address, with a netmask of 255.255.255.0 – the network portion is the first three octets, and the host portion is the last octet), your directed broadcast address is 192.168.1.255.
Setting this property on a Transmission Control Protocol (TCP) socket will have no effect.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ exclusive_address_use() [1/2]

bool xtd::net::sockets::socket::exclusive_address_use ( ) const

Gets a boolean value that specifies whether the xtd::net::sockets::socket allows only one process to bind to a port.

Returns
true if the xtd::net::sockets::socket allows only one socket to bind to a specific port; otherwise, false. The default is true for Windows Server 2003 and Windows XP Service Pack 2, and false for all other versions.
Exceptions
xtd::net::sockets::socket_exceptionThis option is valid for a datagram socket only.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
If xtd::net::sockets::socket::exclusive_address_use is false, multiple sockets can use the xtd::net::sockets::socket::bind method to bind to a specific port; however only one of the sockets can perform operations on the network traffic sent to the port. If more than one socket attempts to use the xtd::net::sockets::socket::bind method to bind to a particular port, then the one with the more specific IP address will handle the network traffic sent to that port.
If xtd::net::sockets::socket::exclusive_address_use is true, the first use of the xtd::net::sockets::socket::bind method to attempt to bind to a particular port, regardless of Internet Protocol (IP) address, will succeed; all subsequent uses of the xtd::net::sockets::socket::bind method to attempt to bind to that port will fail until the original bound socket is destroyed.
This property must be set before xtd::net::sockets::socket::bind is called; otherwise an xtd::invalid_operation_exception will be thrown.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ exclusive_address_use() [2/2]

socket & xtd::net::sockets::socket::exclusive_address_use ( bool  value)

Gets a boolean value that specifies whether the xtd::net::sockets::socket allows only one process to bind to a port.

Parameters
valuetrue if the xtd::net::sockets::socket allows only one socket to bind to a specific port; otherwise, false. The default is true for Windows Server 2003 and Windows XP Service Pack 2, and false for all other versions.
Returns
This current instance.
Exceptions
xtd::net::sockets::socket_exceptionThis option is valid for a datagram socket only.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
xtd::invalid_operation_exceptionxtd::net::sockets::socket::bind has been called for this xtd::net::sockets::socket.
Remarks
If xtd::net::sockets::socket::exclusive_address_use is false, multiple sockets can use the xtd::net::sockets::socket::bind method to bind to a specific port; however only one of the sockets can perform operations on the network traffic sent to the port. If more than one socket attempts to use the xtd::net::sockets::socket::bind method to bind to a particular port, then the one with the more specific IP address will handle the network traffic sent to that port.
If xtd::net::sockets::socket::exclusive_address_use is true, the first use of the xtd::net::sockets::socket::bind method to attempt to bind to a particular port, regardless of Internet Protocol (IP) address, will succeed; all subsequent uses of the xtd::net::sockets::socket::bind method to attempt to bind to that port will fail until the original bound socket is destroyed.
This property must be set before xtd::net::sockets::socket::bind is called; otherwise an xtd::invalid_operation_exception will be thrown.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ handle()

intptr xtd::net::sockets::socket::handle ( ) const
noexcept

Gets the operating system handle for the xtd::net::sockets::socket.

Returns
An intptr that represents the operating system handle for the xtd::net::sockets::socket.
Examples
socket_tcp_ip_v4_without_thread.cpp.

◆ is_bound()

bool xtd::net::sockets::socket::is_bound ( ) const
noexcept

Gets a value that indicates whether the xtd::net::sockets::socket is bound to a specific local port.

Returns
true if the xtd::net::sockets::socket is bound to a local port; otherwise, false.
Remarks
A socket is considered bound to a local port if it is explicitly bound by calling the xtd::net::sockets::socket::bind method, or implicitly bound by calling members like xtd::net::sockets::socket::connect, xtd::net::sockets::socket::send_to, or xtd::net::sockets::socket::receive_from, which use an ephemeral local port (a free port greater than 1024, selected by the operating system.) Servers use the xtd::net::sockets::socket::bind method to bind to a well-known port so that clients may connect to them.

◆ linger_state() [1/2]

xtd::net::sockets::linger_option xtd::net::sockets::socket::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.

Returns
A xtd::net::sockets::sockets::linger_option that specifies how to linger while closing a socket.
Exceptions
xtd::net::sockets::socket_exceptionThis option is valid for a datagram socket only.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
The xtd::net::sockets::socket::linger_state property changes the way xtd::net::sockets::socket::close method behaves. This property when set modifies the conditions under which the connection can be reset by Winsock. Connection resets can still occur based on the IP protocol behavior.
This property controls the length of time that a connection-oriented connection will remain open after a call to xtd::net::sockets::socket::close when data remains to be sent.
When you call methods to send data to a peer, this data is placed in the outgoing network buffer. This property can be used to ensure that this data is sent to the remote host before the xtd::net::sockets::socket::close method drops the connection.
To enable lingering, create a xtd::net::sockets::linger_option instance containing the desired values, and set the xtd::net::sockets::socket::linger_state property to this instance.
The following table describes the behavior of the xtd::net::sockets::socket::close method for the possible values of the xtd::net::sockets::inger_option::enabled property and the xtd::net::sockets::linger_option::linger_time property stored in the xtd::net::sockets::socket::linger_state property.
xtd::net::sockets::linger_state::enabled xtd::net::sockets::linger_state::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 time-out. Discards any pending data. For connection-oriented socket (TCP, for example), Winsock resets the connection.
The IP stack computes the default IP protocol time-out period to use based on the round trip time of the connection. In most cases, the time-out computed by the stack is more relevant than one defined by an application. This is the default behavior for a socket when the xtd::net::sockets::socket::linger_state property is not set.
When the xtd::net::sockets::linger_option::linger_time property stored in the xtd::net::sockets::socket::linger_state property is set greater than the default IP protocol time-out, the default IP protocol time-out will still apply and override.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ linger_state() [2/2]

socket & xtd::net::sockets::socket::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.

Parameters
valueA xtd::net::sockets::sockets::linger_option that specifies how to linger while closing a socket.
Returns
This current instance.
Exceptions
xtd::net::sockets::socket_exceptionThis option is valid for a datagram socket only.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
The xtd::net::sockets::socket::linger_state property changes the way xtd::net::sockets::socket::close method behaves. This property when set modifies the conditions under which the connection can be reset by Winsock. Connection resets can still occur based on the IP protocol behavior.
This property controls the length of time that a connection-oriented connection will remain open after a call to xtd::net::sockets::socket::close when data remains to be sent.
When you call methods to send data to a peer, this data is placed in the outgoing network buffer. This property can be used to ensure that this data is sent to the remote host before the xtd::net::sockets::socket::close method drops the connection.
To enable lingering, create a xtd::net::sockets::linger_option instance containing the desired values, and set the xtd::net::sockets::socket::linger_state property to this instance.
The following table describes the behavior of the xtd::net::sockets::socket::close method for the possible values of the xtd::net::sockets::inger_option::enabled property and the xtd::net::sockets::linger_option::linger_time property stored in the xtd::net::sockets::socket::linger_state property.
xtd::net::sockets::linger_state::enabled xtd::net::sockets::linger_state::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 time-out. Discards any pending data. For connection-oriented socket (TCP, for example), Winsock resets the connection.
The IP stack computes the default IP protocol time-out period to use based on the round trip time of the connection. In most cases, the time-out computed by the stack is more relevant than one defined by an application. This is the default behavior for a socket when the xtd::net::sockets::socket::linger_state property is not set.
When the xtd::net::sockets::linger_option::linger_time property stored in the xtd::net::sockets::socket::linger_state property is set greater than the default IP protocol time-out, the default IP protocol time-out will still apply and override.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ local_end_point()

xtd::sptr< xtd::net::end_point > xtd::net::sockets::socket::local_end_point ( ) const

Gets the local endpoint.

Returns
The xtd::net::end_point that the xtd::net::sockets::socket is using for communications.
Exceptions
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
The xtd::net::sockets::socket::local_end_point property gets an xtd::net::end_point that contains the local IP address and port number to which your xtd::net::sockets::socket is bound. You must cast this xtd::net::end_point to an xtd::net::ip_end_point before retrieving any information. You can then call the xtd::net::ip_end_point::address method to retrieve the local xtd::net::ip_address, and the xtd::net::ip_end_point::port method to retrieve the local port number.
The xtd::net::sockets::socket::local_end_point property is usually set after you make a call to the xtd::net::sockets::socket::bind method. If you allow the system to assign your socket's local IP address and port number, the xtd::net::sockets::socket::local_end_point property will be set after the first I/O operation. For connection-oriented protocols, the first I/O operation would be a call to the xtd::net::sockets::socket::connect or xtd::net::sockets::socket::accept method. For connectionless protocols, the first I/O operation would be any of the send or receive calls.

◆ multicast_loopback() [1/2]

bool xtd::net::sockets::socket::multicast_loopback ( ) const

Gets a value that specifies whether outgoing multicast packets are delivered to the sending application.

Returns
true if the xtd::net::sockets::socket receives outgoing multicast packets; otherwise, false.
Exceptions
xtd::net::sockets::socket_exceptionThis option is valid for a datagram socket only.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
xtd::not_supported_exceptionThe xtd::net::sockets::socket is not in the xtd::net::sockets::address_family::inter_network or xtd::net::sockets::address_family::inter_network_v6 families.
Remarks
Multicast is a scalable method for many-to-many communication on the Internet. A process subscribes to a multicast address; then, any packets sent by a subscribed process are received by every other process subscribed to the multicast address.
Setting this property on a Transmission Control Protocol (TCP) socket has no effect.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ multicast_loopback() [2/2]

socket & xtd::net::sockets::socket::multicast_loopback ( bool  value)

Sets a value that specifies whether outgoing multicast packets are delivered to the sending application.

Parameters
valuetrue if the xtd::net::sockets::socket receives outgoing multicast packets; otherwise, false.
Returns
This current instance.
Exceptions
xtd::net::sockets::socket_exceptionThis option is valid for a datagram socket only.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
xtd::not_supported_exceptionThe xtd::net::sockets::socket is not in the xtd::net::sockets::address_family::inter_network or xtd::net::sockets::address_family::inter_network_v6 families.
Remarks
Multicast is a scalable method for many-to-many communication on the Internet. A process subscribes to a multicast address; then, any packets sent by a subscribed process are received by every other process subscribed to the multicast address.
Setting this property on a Transmission Control Protocol (TCP) socket has no effect.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ no_delay() [1/2]

bool xtd::net::sockets::socket::no_delay ( ) const

Gets a boolean value that specifies whether the stream xtd::net::sockets::socket is using the Nagle algorithm.

Returns
false if the xtd::net::sockets::socket uses the Nagle algorithm; otherwise, true. The default is false.
Exceptions
xtd::net::sockets::socket_exceptionThis option is valid for a datagram socket only.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
The Nagle algorithm is designed to reduce network traffic by causing the socket to buffer small packets and then combine and send them in one packet under certain circumstances. A TCP packet consists of 40 bytes of header plus the data being sent. When small packets of data are sent with TCP, the overhead resulting from the TCP header can become a significant part of the network traffic. On heavily loaded networks, the congestion resulting from this overhead can result in lost datagrams and retransmissions, as well as excessive propagation time caused by congestion. The Nagle algorithm inhibits the sending of new TCP segments when new outgoing data arrives from the user if any previously transmitted data on the connection remains unacknowledged.
The majority of network applications should use the Nagle algorithm.
Setting this property on a User Datagram Protocol (UDP) socket will have no effect.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ no_delay() [2/2]

socket & xtd::net::sockets::socket::no_delay ( bool  value)

Gets a boolean value that specifies whether the stream xtd::net::sockets::socket is using the Nagle algorithm.

Parameters
valuefalse if the xtd::net::sockets::socket uses the Nagle algorithm; otherwise, true. The default is false.
Returns
This current instance.
Exceptions
xtd::net::sockets::socket_exceptionThis option is valid for a datagram socket only.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
The Nagle algorithm is designed to reduce network traffic by causing the socket to buffer small packets and then combine and send them in one packet under certain circumstances. A TCP packet consists of 40 bytes of header plus the data being sent. When small packets of data are sent with TCP, the overhead resulting from the TCP header can become a significant part of the network traffic. On heavily loaded networks, the congestion resulting from this overhead can result in lost datagrams and retransmissions, as well as excessive propagation time caused by congestion. The Nagle algorithm inhibits the sending of new TCP segments when new outgoing data arrives from the user if any previously transmitted data on the connection remains unacknowledged.
The majority of network applications should use the Nagle algorithm.
Setting this property on a User Datagram Protocol (UDP) socket will have no effect.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ protocol_type()

xtd::net::sockets::protocol_type xtd::net::sockets::socket::protocol_type ( ) const
noexcept

Gets the protocol type of the xtd::net::sockets::socket.

Returns
One of the xtd::net::sockets::protocol_type values.
Remarks
The xtd::net::sockets::socket::protocol_type property is set when the xtd::net::sockets::socket is created, and specifies the protocol used by that xtd::net::sockets::socket.

◆ receive_buffer_size() [1/2]

size_t xtd::net::sockets::socket::receive_buffer_size ( ) const

Gets a value that specifies the size of the receive buffer of the xtd::net::sockets::socket.

Returns
An size_t that contains the size, in bytes, of the receive buffer. The default is 8192.
Exceptions
xtd::net::sockets::socket_exceptionThis option is valid for a datagram socket only.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
A larger buffer size potentially reduces the number of empty acknowledgements (TCP packets with no data portion), but might also delay the recognition of connection difficulties. Consider increasing the buffer size if you are transferring large files, or you are using a high bandwidth, high latency connection (such as a satellite broadband provider.)
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ receive_buffer_size() [2/2]

socket & xtd::net::sockets::socket::receive_buffer_size ( size_t  value)

Sets a value that specifies the size of the receive buffer of the xtd::net::sockets::socket.

Parameters
valueAn size_t that contains the size, in bytes, of the receive buffer. The default is 8192.
Returns
This current instance.
Exceptions
xtd::net::sockets::socket_exceptionThis option is valid for a datagram socket only.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
A larger buffer size potentially reduces the number of empty acknowledgements (TCP packets with no data portion), but might also delay the recognition of connection difficulties. Consider increasing the buffer size if you are transferring large files, or you are using a high bandwidth, high latency connection (such as a satellite broadband provider.)
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ receive_timeout() [1/2]

int32 xtd::net::sockets::socket::receive_timeout ( ) const

Gets a value that specifies the amount of time after which a synchronous xtd::net::sockets::socket::receive call will time out.

Returns
The time-out value, in milliseconds. The default value is 0, which indicates an infinite time-out period. Specifying -1 also indicates an infinite time-out period.
Exceptions
xtd::net::sockets::socket_exceptionThis option is valid for a datagram socket only.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
This option applies to synchronous xtd::net::sockets::socket::receive calls only. If the time-out period is exceeded, the xtd::net::sockets::socket::receive method will throw a xtd::net::sockets::socket_exception.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ receive_timeout() [2/2]

socket & xtd::net::sockets::socket::receive_timeout ( int32  value)

Sets a value that specifies the amount of time after which a synchronous xtd::net::sockets::socket::receive call will time out.

Parameters
valueThe time-out value, in milliseconds. The default value is 0, which indicates an infinite time-out period. Specifying -1 also indicates an infinite time-out period.
Returns
This current instance.
Exceptions
xtd::net::sockets::socket_exceptionThis option is valid for a datagram socket only.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
xtd::argument_out_of_range_exceptionThe value specified for a set operation is less than -1.
Remarks
This option applies to synchronous xtd::net::sockets::socket::receive calls only. If the time-out period is exceeded, the xtd::net::sockets::socket::receive method will throw a xtd::net::sockets::socket_exception.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ remote_end_point()

xtd::sptr< xtd::net::end_point > xtd::net::sockets::socket::remote_end_point ( ) const

Gets the remote endpoint.

Returns
The xtd::net::end_point with which the xtd::net::sockets::socket is communicating.
Exceptions
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
If you are using a connection-oriented protocol, the xtd::net::sockets::socket::remote_end_point property gets the xtd::net::sockets::end_point that contains the remote IP address and port number to which the xtd::net::sockets::socket is connected. If you are using a connectionless protocol, xtd::net::sockets::socket::remote_end_point contains the default remote IP address and port number with which the xtd::net::sockets::socket will communicate. You must cast this xtd::net::end_point to an xtd::net::ip_end_point before retrieving any information. You can then call the xtd::net::ip_end_point::address method to retrieve the remote xtd::net::ip_address, and the xtd::net::ip_end_point::port method to retrieve the remote port number.
The xtd::net::sockets::socket::remote_end_point is set after a call to either xtd::net::sockets::socket::accept or xtd::net::sockets::socket::connect. If you try to access this property earlier, xtd::net::sockets::socket::remote_end_point will throw a xtd::net::sockets::socket_exception. If you receive a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation for a detailed description of the error.

◆ send_buffer_size() [1/2]

size_t xtd::net::sockets::socket::send_buffer_size ( ) const

Gets a value that specifies the size of the send buffer of the xtd::net::sockets::socket.

Returns
An size_t that contains the size, in bytes, of the send buffer. The default is 8192.
Exceptions
xtd::net::sockets::socket_exceptionThis option is valid for a datagram socket only.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
A larger buffer size might delay the recognition of connection difficulties. Consider increasing the buffer size if you are transferring large files, or you are using a high bandwidth, high latency connection (such as a satellite broadband provider.)
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ send_buffer_size() [2/2]

socket & xtd::net::sockets::socket::send_buffer_size ( size_t  value)

Sets a value that specifies the size of the send buffer of the xtd::net::sockets::socket.

Parameters
valueAn size_t that contains the size, in bytes, of the send buffer. The default is 8192.
Returns
This current instance.
Exceptions
xtd::net::sockets::socket_exceptionThis option is valid for a datagram socket only.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
A larger buffer size might delay the recognition of connection difficulties. Consider increasing the buffer size if you are transferring large files, or you are using a high bandwidth, high latency connection (such as a satellite broadband provider.)
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ send_timeout() [1/2]

int32 xtd::net::sockets::socket::send_timeout ( ) const

Gets a value that specifies the amount of time after which a synchronous xtd::net::sockets::socket::send call will time out.

Returns
The time-out value, in milliseconds. If you set the property with a value between 1 and 499, the value will be changed to 500. The default value is 0, which indicates an infinite time-out period. Specifying -1 also indicates an infinite time-out period.
Exceptions
xtd::net::sockets::socket_exceptionThis option is valid for a datagram socket only.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
This option applies to synchronous Send calls only. If the time-out period is exceeded, the Send method will throw a xtd::net::sockets::socket::socket_exception.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ send_timeout() [2/2]

socket & xtd::net::sockets::socket::send_timeout ( int32  value)

Sets a value that specifies the amount of time after which a synchronous xtd::net::sockets::socket::send call will time out.

Parameters
valueThe time-out value, in milliseconds. If you set the property with a value between 1 and 499, the value will be changed to 500. The default value is 0, which indicates an infinite time-out period. Specifying -1 also indicates an infinite time-out period.
Returns
This current instance.
Exceptions
xtd::net::sockets::socket_exceptionThis option is valid for a datagram socket only.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
xtd::argument_out_of_range_exceptionThe value specified for a set operation is less than -1.
Remarks
This option applies to synchronous Send calls only. If the time-out period is exceeded, the Send method will throw a xtd::net::sockets::socket::socket_exception.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ socket_type()

xtd::net::sockets::socket_type xtd::net::sockets::socket::socket_type ( ) const
noexcept

Gets the type of the xtd::net::sockets::socket.

Returns
One of the xtd::net::sockets::socket_type values.
Remarks
xtd::net::sockets::socket::socket_type is read-only and is set when the xtd::net::sockets::socket is created.

◆ ttl() [1/2]

xtd::byte xtd::net::sockets::socket::ttl ( ) const

Gets a value that specifies the Time To Live (TTL) value of Internet Protocol (IP) packets sent by the xtd::net::sockets::socket.

Returns
The TTL value.
Exceptions
xtd::net::sockets::socket_exceptionThis option is valid for a datagram socket only.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
xtd::not_supported_exceptionhe xtd::net::sockets::socket is not in the xtd::net::sockets::address_family::inter_network or xtd::net::sockets::address_family::inter_network_v6 families.
Remarks
The TTL value indicates the maximum number of routers the packet can traverse before the router discards the packet and an Internet Control Message Protocol (ICMP) "TTL exceeded" error message is returned to the sender.
The TTL value may be set to a value from 0 to 255. When this property is not set, the default TTL value for a socket is 32.
Setting this property on a Transmission Control Protocol (TCP) socket is ignored by the TCP/IP stack if a successful connection has been established using the socket.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ ttl() [2/2]

socket & xtd::net::sockets::socket::ttl ( xtd::byte  value)

Sets a value that specifies the Time To Live (TTL) value of Internet Protocol (IP) packets sent by the xtd::net::sockets::socket.

Parameters
valueThe TTL value.
Returns
This current instance.
Exceptions
xtd::net::sockets::socket_exceptionThis option is valid for a datagram socket only.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
xtd::not_supported_exceptionhe xtd::net::sockets::socket is not in the xtd::net::sockets::address_family::inter_network or xtd::net::sockets::address_family::inter_network_v6 families.
Remarks
The TTL value indicates the maximum number of routers the packet can traverse before the router discards the packet and an Internet Control Message Protocol (ICMP) "TTL exceeded" error message is returned to the sender.
The TTL value may be set to a value from 0 to 255. When this property is not set, the default TTL value for a socket is 32.
Setting this property on a Transmission Control Protocol (TCP) socket is ignored by the TCP/IP stack if a successful connection has been established using the socket.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ os_supports_ip_v4()

static bool xtd::net::sockets::socket::os_supports_ip_v4 ( )
staticnoexcept

Indicates whether the underlying operating system and network adaptors support Internet Protocol version 4 (IPv4).

Returns
true if the operating system and network adaptors support the IPv4 protocol; otherwise, false.
Remarks
The operating system may support both IPv4 and IPv6 protocols.

◆ os_supports_ip_v6()

static bool xtd::net::sockets::socket::os_supports_ip_v6 ( )
staticnoexcept

Indicates whether the underlying operating system and network adaptors support Internet Protocol version 6 (IPv6).

Returns
true if the operating system and network adaptors support the IPv6 protocol; otherwise, false.
Remarks
The operating system may support both IPv4 and IPv6 protocols.

◆ accept()

socket xtd::net::sockets::socket::accept ( )

Creates a new xtd::net::sockets::socket for a newly created connection.

Returns
A xtd::net::sockets::socket for a newly created connection.
Exceptions
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
xtd::invalid_operation_exceptionThe accepting socket is not listening for connections. You must call xtd::net::sockets::socket::bind and xtd::net::sockets::socket::listen before calling xtd::net::sockets::socket::accept().
Remarks
xtd::net::sockets::socket::accept synchronously extracts the first pending connection request from the connection request queue of the listening socket, and then creates and returns a new xtd::net::sockets::socket. You cannot use this returned xtd::net::sockets::socket to accept any additional connections from the connection queue. However, you can call the xtd::net::sockets::socket::remote_end_point method of the returned xtd::net::sockets::socket to identify the remote host's network address and port number.
In blocking mode, xtd::net::sockets::socket::accept blocks until an incoming connection attempt is queued. Once a connection is accepted, the original xtd::net::sockets::socket continues queuing incoming connection requests until you close it.
If you call this method using a non-blocking xtd::net::sockets::socket, and no connection requests are queued, xtd::net::sockets::socket::accept throws a xtd::net::sockets::socket_exception. If you receive a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.
Note
Before calling the xtd::net::sockets::socket::accept method, you must first call the xtd::net::sockets::socket::listen method to listen for and queue incoming connection requests.
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ accept_async()

bool xtd::net::sockets::socket::accept_async ( xtd::net::sockets::socket_async_event_args e)

Begins an asynchronous operation to accept an incoming connection attempt.

Parameters
eThe xtd::net::sockets::socket::socket_async_event_args object to use for this asynchronous socket operation.
Returns
true if the I/O operation is pending. The Completed event on the e parameter will be raised upon completion of the operation. false if the I/O operation completed synchronously. The Completed event on the e parameter will not be raised and the e object passed as a parameter may be examined immediately after the method call returns to retrieve the result of the operation.
Exceptions
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
xtd::argument_exceptionAn argument is not valid. This exception occurs if the buffer provided is not large enough. The buffer must be at least 2 * (sizeof(SOCKADDR_STORAGE + 16) bytes. This exception also occurs if multiple buffers are specified, the xtd::net::sockets::socket_async_event_args::buffer_list property is not empty.
xtd::invalid_operation_exceptionThe accepting socket is not listening for connections. You must call xtd::net::sockets::socket::bind and xtd::net::sockets::socket::listen before calling xtd::net::sockets::socket::accept().
Remarks
Connection-oriented protocols can use the xtd::net::sockets::socket::accept_async method to asynchronously process incoming connection attempts. Accepting connections asynchronously gives you the ability to send and receive data within a separate execution thread. Before calling the xtd::net::sockets::socket::accept_async method, you must call the xtd::net::sockets::socket::listen method to listen for and queue incoming connection requests.
To be notified of completion, you must create a callback method that implements the xtd::delegate<const xtd::net::sockets::socket_async_event_args&> delegate and hook it to the xtd::net::sockets::socket_async_event_args::completed event.
The following properties and events on the xtd::net::sockets::socket_async_event_args object are required:
The caller can optionally specify an existing xtd::net::sockets::socket to use for the incoming connection by specifying the xtd::net::sockets::socket to use with the xtd::net::sockets::socket_async_eventArgs::accept_socket property.
If the xtd::net::sockets::socket_async_event_args::accept_socket property is empty, a new xtd::net::sockets::socket is constructed with the same xtd::net::sockets::address_family, xtd::net::sockets::socket_type, and xtd::net::sockets::protocol_type as the current xtd::net::sockets::socket and set as the xtd::net::sockets::socket_async_event_args::accept_socket property.
The caller may set the xtd::net::sockets::socket_async_event_args::user_token property to any user state object desired before calling the xtd::net::sockets::socket::accept_async method, so that the information will be retrievable in the callback method. If the callback needs more information than a single object, a small class can be created to hold the other required state information as members.
Optionally, a buffer may be provided in which to receive the initial block of data on the socket after the xtd::net::sockets::socket::connect_async method succeeds. In this case, the xtd::net::sockets::socket_async_event_args::buffer property needs to be set to the buffer containing the data to receive and the xtd::net::sockets::socket_async_event_args::count property needs to be set to the maximum number of bytes of data to receive in the buffer. These properties can be set using the xtd::net::sockets::socket_async_event_args::set_buffer method. Part of the buffer passed in will be consumed internally for use by the underlying Winsock AcceptEx call. This means that the amount of data returned will always be less than the value of the xtd::net::sockets::socket::async_event_args::count property on the xtd::net::sockets::socket_async_event_args instance provided. The amount of the buffer used internally varies based on the address family of the socket. The minimum buffer size required is 288 bytes. If a larger buffer size is specified, then the xtd::net::sockets::socket will expect some extra data other than the address data received by the Winsock AcceptEx call and will wait until this extra data is received. If a timeout occurs, the connection is reset. So if extra data is expected of a specific amount, then the buffer size should be set to the minimum buffer size plus this amount.
The completion callback method should examine the xtd::net::sockets::socket_async_event_args::socket_error property to determine if the xtd::net::sockets::socket::accept_async operation was successful.
The xtd::net::sockets::socket_async_event_args::completed event can occur in some cases when no connection has been accepted and cause the xtd::net::sockets::socket_async_event_args::socket_error property to be set to xtd::net::sockets::socket_error::connection_reset. This can occur as a result of port scanning using a half-open SYN type scan (a SYN -> SYN-ACK -> RST sequence). Applications using the xtd::net::sockets::socket::accept_async method should be prepared to handle this condition.

◆ begin_accept()

xtd::sptr< xtd::iasync_result > xtd::net::sockets::socket::begin_accept ( xtd::async_callback  callback,
const std::any &  state 
)

Begins an asynchronous operation to accept an incoming connection attempt.

Parameters
callbackThe xtd::async_callback delegate.
stateAn object that contains state information for this request.
Returns
An xtd::iasync_result that references the asynchronous connection.
Exceptions
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
xtd::invalid_operation_exceptionThe accepting socket is not listening for connections. You must call xtd::net::sockets::socket::bind and xtd::net::sockets::socket::listen before calling xtd::net::sockets::socket::accept().
xtd::invalid_operation_exceptionThe accepting socket is not listening for connections. You must call xtd::net::sockets::socket::bind and xtd::net::sockets::socket::listen before calling xtd::net::sockets::socket::accept().
Remarks
Connection-oriented protocols can use the xtd::net::sockets::socket::begin_accept method to asynchronously process incoming connection attempts. Accepting connections asynchronously gives you the ability to send and receive data within a separate execution thread. Before calling the xtd::net::sockets::socket::begin_accept method, you must call the xtd::net::sockets::socket::socket::listen method to listen for and queue incoming connection requests.
You must create a callback method that implements the xtd::async_callback delegate and pass its name to the xtd::net::sockets::socket::begin_accept method. To do this, at the very minimum, you must pass the listening xtd::net::sockets::socket::socket object to xtd::net::sockets::socket::begin_accept through the state parameter. If your callback needs more information, you can create a small class to hold the xtd::net::sockets::socket::socket and the other required information. Pass an instance of this class to the xtd::net::sockets::socket::begin_accept method through the state parameter.
Your callback method should invoke the xtd::net::sockets::socket::end_accept method. When your application calls xtd::net::sockets::socket::begin_accept, the system usually uses a separate thread to execute the specified callback method and blocks on xtd::net::sockets::socket::end_accept until a pending connection is retrieved. xtd::net::sockets::socket::end_accept will return a new xtd::net::sockets::socket::socket object that you can use to send and receive data with the remote host. You cannot use this returned xtd::net::sockets::socket::socket to accept any additional connections from the connection queue. If you want the original thread to block after you call the xtd::net::sockets::socket::begin_accept method, use xtd::threading::mutex::wait_one. Call the xtd::threading::mutex::release_mutex method on a xtd::threading::mutex in the callback method when you want the original thread to continue executing.
The system may also use the calling thread to invoke the callback method. In this case, the xtd::iasync_result::completed_synchronously property on the returned xtd::iasync_result will be set to indicate that the xtd::net::sockets::socket::begin_accept method completed synchronously.
To cancel a pending call to the xtd::net::sockets::socket::begin_accept method, close the xtd::net::sockets::socket::socket. When the xtd::sockets::socket::close method is called while an asynchronous operation is in progress, the callback provided to the xtd::net::sockets::socket::begin_accept method is called. A subsequent call to the xtd::net::sockets::socket::end_accept method will throw an xtd::object_closed_exception to indicate that the operation has been cancelled.
Note
You can use the xtd::net::sockets::socket::remote_end_point property of the returned xtd::net::sockets::socket::socket to identify the remote host's network address and port number.
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ begin_connect() [1/4]

template<typename end_point_t >
xtd::sptr< xtd::iasync_result > xtd::net::sockets::socket::begin_connect ( const end_point_t &  remote_end_point,
xtd::async_callback  callback,
const std::any &  state 
)
inline

Begins an asynchronous request for a remote host connection.

Parameters
remote_end_pointAn xtd::net::end_point that represents the remote host.
callbackThe xtd::async_callback delegate.
stateAn object that contains state information for this request.
Returns
An xtd::iasync_result that references the asynchronous connection.
Exceptions
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
xtd::invalid_operation_exceptionThe accepting socket is not listening for connections. You must call xtd::net::sockets::socket::bind and xtd::net::sockets::socket::listen before calling xtd::net::sockets::socket::accept().
Remarks
If you are using a connection-oriented protocol, the xtd::net::sockets::socket::begin_connect method starts an asynchronous request for a connection to the remote_end_point parameter. If you are using a connectionless protocol, xtd::net::sockets::socket::begin_connect establishes a default remote host. Connecting or setting the default remote host asynchronously gives you the ability to send and receive data within a separate execution thread.
You can create a callback method that implements the xtd::async_callback delegate and pass its name to the xtd::net::sockets::socket::begin_connect method. At the very minimum, you must pass the xtd::net::sockets::socket::socket to xtd::net::sockets::socket::begin_connect through the state parameter. If your callback needs more information, you can create a small class to hold the xtd::net::sockets::socket::socket, and the other required information. Pass an instance of this class to the xtd::net::sockets::socket::begin_connect method through the state parameter.
Your callback method should invoke the xtd::net::sockets::socket::end_connect method. When your application calls xtd::net::sockets::socket::begin_connect, the system will use a separate thread to execute the specified callback method, and will block on xtd::net::sockets::socket::end_connect until the xtd::net::sockets::socket::socket connects successfully or throws an exception. If you want the original thread to block after you call the xtd::net::sockets::socket::begin_connect method, use xtd::threading::mutex::wait_one. Call the xtd::threading::mutex::release_mutex method on a xtd::threading::mutex in the callback method when you want the original thread to continue executing.
If you are using a connectionless protocol such as UDP, you do not have to call xtd::net::sockets::socket::begin_connect before sending and receiving data. You can use xtd::net::sockets::socket::begin_send_to and xtd::net::sockets::socket::begin_receive_from to communicate with a remote host. If you do call xtd::net::sockets::socket::begin_connect, any datagrams that arrive from an address other than the specified default will be discarded. If you wish to set your default remote host to a broadcast address, you must first call xtd::net::sockets::socket::set_socket_option and set xtd::net::sockets::socket::socket_option_name::broadcast to true. If you cannot, xtd::net::sockets::socket::begin_connect will throw a xtd::net::sockets::socket_exception.
If you are using a connection-oriented protocol and do not call xtd::net::sockets::socket::bind before calling xtd::net::sockets::socket::begin_connect, the underlying service provider will assign the most appropriate local network address and port number. If you are using a connectionless protocol, the service provider will not assign a local network address and port number until you call the xtd::net::sockets::socket::begin_send or xtd::net::sockets::socket::receive_from method. If you want to change the default remote host, call the xtd::net::sockets::socket::begin_connect method again with the desired endpoint.
To cancel a pending call to the xtd::net::sockets::socket::begin_connect method, close the xtd::net::sockets::socket::socket. When the xtd::net::sockets::socket::socket::close method is called while an asynchronous operation is in progress, the callback provided to the xtd::net::sockets::socket::begin_connect method is called. A subsequent call to the xtd::net::sockets::socket::end_connect method will throw an xtd::object_closed_exception to indicate that the operation has been cancelled.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.
If this socket has previously been disconnected, then xtd::net::sockets::socket::begin_connect must be called on a thread that will not exit until the operation is complete. This is a limitation of the underlying provider.
Examples
socket_tcp_ip_v4_without_thread.cpp.

◆ begin_connect() [2/4]

xtd::sptr< xtd::iasync_result > xtd::net::sockets::socket::begin_connect ( const xtd::net::ip_address address,
uint16  port,
xtd::async_callback  callback,
const std::any &  state 
)

Begins an asynchronous request for a remote host connection. The host is specified by an xtd::net::ip_address and a port number.

Parameters
addressThe xtd::net::ip_address of the remote host.
portThe port number of the remote host.
callbackThe xtd::async_callback delegate.
stateAn object that contains state information for this request.
Returns
An xtd::iasync_result that references the asynchronous connection.
Exceptions
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
xtd::invalid_operation_exceptionThe accepting socket is not listening for connections. You must call xtd::net::sockets::socket::bind and xtd::net::sockets::socket::listen before calling xtd::net::sockets::socket::accept().
Remarks
The asynchronous xtd::net::sockets::socket::begin_connect operation must be completed by calling the xtd::net::sockets::socket::end_connect method. Typically, the method is invoked by the callback delegate.
This method does not block until the operation is complete. To block until the operation is complete, use one of the xtd::net::sockets::socket::connect method overloads, or xtd::net::sockets::socket::end_connect.
To cancel a pending call to the xtd::net::sockets::socket::begin_connect method, close the xtd::net::sockets::socket::socket. When the xtd::net::sockets::socket::socket::close method is called while an asynchronous operation is in progress, the callback provided to the xtd::net::sockets::socket::begin_connect method is called. A subsequent call to the xtd::net::sockets::socket::end_connect method will throw an xtd::object_closed_exception to indicate that the operation has been cancelled.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.
If this socket has previously been disconnected, then xtd::net::sockets::socket::begin_connect must be called on a thread that will not exit until the operation is complete. This is a limitation of the underlying provider. Also the xtd::net::end_point that is used must be different.

◆ begin_connect() [3/4]

xtd::sptr< xtd::iasync_result > xtd::net::sockets::socket::begin_connect ( const std::vector< xtd::net::ip_address > &  addresses,
uint16  port,
xtd::async_callback  callback,
const std::any &  state 
)

Begins an asynchronous request for a remote host connection. The host is specified by an xtd::net::ip_address array and a port number.

Parameters
addressesAt least one xtd::net::ip_address, designating the remote host.
portThe port number of the remote host.
callbackAn xtd::async_callback delegate that references the method to invoke when the connect operation is complete.
stateA user-defined object that contains information about the connect operation. This object is passed to the requestCallback delegate when the operation is complete.
Returns
An xtd::iasync_result that references the asynchronous connection.
Exceptions
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
xtd::invalid_operation_exceptionThe accepting socket is not listening for connections. You must call xtd::net::sockets::socket::bind and xtd::net::sockets::socket::listen before calling xtd::net::sockets::socket::accept().
Remarks
The asynchronous xtd::net::sockets::socket::begin_connect operation must be completed by calling the xtd::net::sockets::socket::end_connect method. Typically, the method is invoked by the callback delegate.
This method does not block until the operation is complete. To block until the operation is complete, use one of the xtd::net::sockets::socket::connect method overloads.
To cancel a pending call to the xtd::net::sockets::socket::begin_connect method, close the xtd::net::sockets::socket::socket. When the xtd::net::sockets::socket::socket::close method is called while an asynchronous operation is in progress, the callback provided to the xtd::net::sockets::socket::begin_connect method is called. A subsequent call to the xtd::net::sockets::socket::end_connect method will throw an xtd::object_closed_exception to indicate that the operation has been cancelled.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.
If this socket has previously been disconnected, then xtd::net::sockets::socket::begin_connect must be called on a thread that will not exit until the operation is complete. This is a limitation of the underlying provider. Also the xtd::net::end_point that is used must be different.

◆ begin_connect() [4/4]

xtd::sptr< xtd::iasync_result > xtd::net::sockets::socket::begin_connect ( const xtd::string host,
uint16  port,
xtd::async_callback  callback,
const std::any &  state 
)

Begins an asynchronous request for a remote host connection. The host is specified by a host name and a port number.

Parameters
hostThe name of the remote host.
portThe port number of the remote host.
callbackThe xtd::async_callback delegate.
stateAn object that contains state information for this request.
Returns
An xtd::iasync_result that references the asynchronous connection.
Exceptions
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
xtd::invalid_operation_exceptionThe accepting socket is not listening for connections. You must call xtd::net::sockets::socket::bind and xtd::net::sockets::socket::listen before calling xtd::net::sockets::socket::accept().
Remarks
The asynchronous xtd::net::sockets::socket::begin_connect operation must be completed by calling the xtd::net::sockets::socket::end_connect method. Typically, the method is invoked by the callback delegate.
This method does not block until the operation is complete. To block until the operation is complete, use one of the xtd::net::sockets::socket::connect method overloads.
To cancel a pending call to the xtd::net::sockets::socket::begin_connect method, close the xtd::net::sockets::socket::socket. When the xtd::net::sockets::socket::socket::close method is called while an asynchronous operation is in progress, the callback provided to the xtd::net::sockets::socket::begin_connect method is called. A subsequent call to the xtd::net::sockets::socket::end_connect method will throw an xtd::object_closed_exception to indicate that the operation has been cancelled.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.
If this socket has previously been disconnected, then xtd::net::sockets::socket::begin_connect must be called on a thread that will not exit until the operation is complete. This is a limitation of the underlying provider. Also the xtd::net::end_point that is used must be different.

◆ begin_disconnect()

xtd::sptr< xtd::iasync_result > xtd::net::sockets::socket::begin_disconnect ( bool  reuse_socket,
xtd::async_callback  callback,
const std::any &  state 
)

Begins an asynchronous request to disconnect from a remote endpoint.

Parameters
reuse_sockettrue if this socket can be reused after the connection is closed; otherwise, false.
callbackThe xtd::async_callback delegate.
stateAn object that contains state information for this request.
Returns
An xtd::iasync_result that references the asynchronous connection.
Exceptions
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
xtd::invalid_operation_exceptionThe accepting socket is not listening for connections. You must call xtd::net::sockets::socket::bind and xtd::net::sockets::socket::listen before calling xtd::net::sockets::socket::accept().
Remarks
If you are using a connection-oriented protocol, you can call the xtd::net::sockets::socket::begin_disconnect method to request a disconnect from a remote endpoint. If reuse_socket is true, you can reuse the socket.
The xtd::net::sockets::socket::begin_disconnect method uses a separate thread to invoke the specified callback method. The xtd::net::sockets::socket::end_disconnect method blocks until the pending disconnect is complete.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ begin_receive() [1/2]

xtd::sptr< xtd::iasync_result > xtd::net::sockets::socket::begin_receive ( std::vector< xtd::byte > &  buffer,
size_t  offset,
size_t  size,
xtd::net::sockets::socket_flags  socket_flags,
xtd::async_callback  callback,
const std::any &  state 
)

Begins to asynchronously receive data from a connected xtd::net::sockets::socket::socket.

Parameters
bufferAn array of type xtd::byte that is the storage location for the received data.
offsetThe zero-based position in the buffer parameter at which to store the received data.
sizeThe number of bytes to receive.
socket_flagsA bitwise combination of the xtd::net::sockets::socket_flags values.
callbackThe xtd::async_callback delegate.
stateAn object that contains state information for this request.
Returns
An xtd::iasync_result that references the asynchronous connection.
Exceptions
xtd::argument_out_of_range_exceptionsize is less than 0 or exceeds the size of the buffer.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
xtd::invalid_operation_exceptionThe accepting socket is not listening for connections. You must call xtd::net::sockets::socket::bind and xtd::net::sockets::socket::listen before calling xtd::net::sockets::socket::accept().
Remarks
The asynchronous xtd::net::sockets::socket::begin_receive operation must be completed by calling the xtd::net::sockets::socket::end_receive method. Typically, the method is invoked by the callback delegate.
This method does not block until the operation is complete. To block until the operation is complete, use one of the xtd::net::sockets::socket::receive method overloads.
To cancel a pending xtd::net::sockets::socket::begin_receive, call the xtd::net::sockets::socket::socket::close method.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.
All I/O initiated by a given thread is canceled when that thread exits. A pending asynchronous operation can fail if the thread exits before the operation completes.
state is an instantiation of a user-defined class.

◆ begin_receive() [2/2]

xtd::sptr< xtd::iasync_result > xtd::net::sockets::socket::begin_receive ( std::vector< xtd::byte > &  buffer,
size_t  offset,
size_t  size,
xtd::net::sockets::socket_flags  socket_flags,
xtd::net::sockets::socket_error error_code,
xtd::async_callback  callback,
const std::any &  state 
)

Begins to asynchronously receive data from a connected xtd::net::sockets::socket::socket.

Parameters
bufferAn array of type xtd::byte that is the storage location for the received data.
offsetThe zero-based position in the buffer parameter at which to store the received data.
sizeThe number of bytes to receive.
socket_flagsA bitwise combination of the xtd::net::sockets::socket_flags values.
error_codeA xtd::net::sockets::socket_error object that stores the socket error.
callbackThe xtd::async_callback delegate.
stateAn object that contains state information for this request.
Returns
An xtd::iasync_result that references the asynchronous connection.
Exceptions
xtd::argument_out_of_range_exceptionsize is less than 0 or exceeds the size of the buffer.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
xtd::invalid_operation_exceptionThe accepting socket is not listening for connections. You must call xtd::net::sockets::socket::bind and xtd::net::sockets::socket::listen before calling xtd::net::sockets::socket::accept().
Remarks
The asynchronous xtd::net::sockets::socket::begin_receive operation must be completed by calling the xtd::net::sockets::socket::end_receive method. Typically, the method is invoked by the callback delegate.
This method does not block until the operation is complete. To block until the operation is complete, use one of the xtd::net::sockets::socket::receive method overloads.
To cancel a pending xtd::net::sockets::socket::begin_receive, call the xtd::net::sockets::socket::socket::close method.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.
All I/O initiated by a given thread is canceled when that thread exits. A pending asynchronous operation can fail if the thread exits before the operation completes.
state is an instantiation of a user-defined class.

◆ begin_receive_from()

xtd::sptr< xtd::iasync_result > xtd::net::sockets::socket::begin_receive_from ( std::vector< xtd::byte > &  buffer,
size_t  offset,
size_t  size,
xtd::net::sockets::socket_flags  socket_flags,
xtd::net::end_point remote_end_point,
xtd::async_callback  callback,
const std::any &  state 
)

Begins to asynchronously receive data from a specified network device.

Parameters
bufferAn array of type xtd::byte that is the storage location for the received data.
offsetThe zero-based position in the buffer parameter at which to store the data.
sizeThe number of bytes to receive.
socket_flagsA bitwise combination of the xtd::net::sockets::socket_flags values.
remote_end_pointAn xtd::net::end_point that represents the source of the data.
callbackThe xtd::async_callback delegate.
stateAn object that contains state information for this request.
Returns
An xtd::iasync_result that references the asynchronous connection.
Exceptions
xtd::argument_out_of_range_exceptionsize is less than 0 or exceeds the size of the buffer.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
xtd::invalid_operation_exceptionThe accepting socket is not listening for connections. You must call xtd::net::sockets::socket::bind and xtd::net::sockets::socket::listen before calling xtd::net::sockets::socket::accept().
Remarks
The xtd::net::sockets::socket::begin_receive_from method starts asynchronously reading connectionless datagrams from a remote host. Calling the xtd::net::sockets::socket::begin_receive_from method gives you the ability to receive data within a separate execution thread.
You can create a callback method that implements the xtd::async_callback delegate and pass its name to the xtd::net::sockets::socket::begin_receive_from method. To do this, at the very minimum, your state parameter must contain the connected or default xtd::net::sockets::socket::socket being used for communication. If your callback needs more information, you can create a small class to hold the xtd::net::sockets::socket::socket and the other required information. Pass an instance of this class to the xtd::net::sockets::socket::begin_receive_from method through the state parameter.
Your callback method should invoke the xtd::net::sockets::socket::end_receive_from method. When your application calls xtd::net::sockets::socket::begin_receive_from, the system will use a separate thread to execute the specified callback method, and it will block on xtd::net::sockets::socket::end_receive_from until the xtd::net::sockets::socket::socket reads data or throws an exception. If you want the original thread to block after you call the xtd::net::sockets::socket::begin_receive_from method, use xtd::threading::mutex::wait_one. Call the xtd::threading::mutex::release_mutex method on a xtd::threading::mutex in the callback method when you want the original thread to continue executing.
Note
Before calling xtd::net::sockets::socket::begin_receive_from, you must explicitly bind the xtd::net::sockets::socket::socket to a local endpoint using the xtd::net::sockets::socket::bind method, or xtd::net::sockets::socket::begin_receive_from will throw a xtd::net::sockets::socket_exception.
Remarks
This method reads data into the buffer parameter, and captures the remote host endpoint from which the data is sent. For information on how to retrieve this endpoint, refer to xtd::net::sockets::socket::end_receive_from. This method is most useful if you intend to asynchronously receive connectionless datagrams from an unknown host or multiple hosts. In these cases, xtd::net::sockets::socket::begin_receive_from will read the first enqueued datagram received into the local network buffer. If the datagram you receive is larger than the size of buffer, the xtd::net::sockets::socket::begin_receive_from method will fill buffer with as much of the message as is possible, and throw a xtd::net::sockets::socket_exception. If you are using an unreliable protocol, the excess data will be lost. If you are using a reliable protocol, the excess data will be retained by the service provider and you can retrieve it by calling the xtd::net::sockets::socket::begin_receive_from method with a large enough buffer.
To guarantee that the remote host endpoint is always returned, an application should explicitly bind the xtd::net::sockets::socket::socket to a local endpoint using the xtd::net::sockets::socket::bind method and then call the xtd::net::sockets::socket::set_socket_option method with the optionLevel parameter set to IP or IPv6 as appropriate, the option_name parameter set to xtd::net::sockets::socket_option_name::packet_information, and the optionValue parameter to enable this option before calling the xtd::net::sockets::socket::begin_receive_from method. Otherwise, it is possible for the remote host endpoint to not be returned when the sender has sent a number of datagrams before the receiver has called the xtd::net::sockets::socket::begin_receive_from method.
Although xtd::net::sockets::socket::begin_receive_from is intended for connectionless protocols, you can use a connection-oriented protocol as well. If you choose to do so, you must first either establish a remote host connection by calling the xtd::net::sockets::socket::connect / xtd::net::sockets::socket::begin_connect method or accept an incoming connection request by calling the xtd::net::sockets::socket::accept or xtd::net::sockets::socket::begin_accept method. If you call the xtd::net::sockets::socket::begin_receive_from method before establishing or accepting a connection, you will get a xtd::net::sockets::socket_exception. You can also establish a default remote host for a connectionless protocol prior to calling the xtd::net::sockets::socket::begin_receive_from method. In either of these cases, the xtd::net::sockets::socket::begin_receive_from method will ignore the remote_end_point parameter and only receive data from the connected or default remote host.
With connection-oriented sockets, xtd::net::sockets::socket::begin_receive_from will read as much data as is available up to the number of bytes specified by the size parameter.
To cancel a pending xtd::net::sockets::socket::begin_receive_from, call the xtd::net::sockets::socket::socket::close method.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ begin_receive_message_from()

xtd::sptr< xtd::iasync_result > xtd::net::sockets::socket::begin_receive_message_from ( std::vector< xtd::byte > &  buffer,
size_t  offset,
size_t  size,
xtd::net::sockets::socket_flags  socket_flags,
xtd::net::end_point remote_end_point,
xtd::async_callback  callback,
const std::any &  state 
)

Begins to asynchronously receive the specified number of bytes of data into the specified location of the data buffer, using the specified xtd::net::sockets::socket_flags, and stores the endpoint and packet information.

Parameters
bufferAn array of type xtd::byte that is the storage location for the received data.
offsetThe zero-based position in the buffer parameter at which to store the data.
sizeThe number of bytes to receive.
socket_flagsA bitwise combination of the xtd::net::sockets::socket_flags values.
remote_end_pointAn xtd::net::end_point that represents the source of the data.
callbackThe xtd::async_callback delegate.
stateAn object that contains state information for this request.
Returns
An xtd::iasync_result that references the asynchronous connection.
Exceptions
xtd::argument_out_of_range_exceptionsize is less than 0 or exceeds the size of the buffer.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
xtd::invalid_operation_exceptionThe accepting socket is not listening for connections. You must call xtd::net::sockets::socket::bind and xtd::net::sockets::socket::listen before calling xtd::net::sockets::socket::accept().
Remarks
The asynchronous receive operation must be completed by calling the xtd::net::sockets::socket::end_receive_message_from method. Typically, the method is invoked by the callback delegate.
This method does not block until the operation completes. To block until the operation completes, use the xtd::net::sockets::socket::receive_message_from method.
To cancel a pending xtd::net::sockets::socket::begin_receive_message_from, call the xtd::net::sockets::socket::socket::close method.
This method reads data into the buffer parameter, and captures the remote host endpoint from which the data is sent, as well as information about the received packet. For information on how to retrieve this endpoint, refer to xtd::net::sockets::socket::end_receive_from. This method is most useful if you intend to asynchronously receive connectionless datagrams from an unknown host or multiple hosts.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ begin_send() [1/2]

xtd::sptr< xtd::iasync_result > xtd::net::sockets::socket::begin_send ( const std::vector< xtd::byte > &  buffer,
size_t  offset,
size_t  size,
xtd::net::sockets::socket_flags  socket_flags,
xtd::async_callback  callback,
const std::any &  state 
)

Sends data asynchronously to a connected xtd::net::sockets::socket::socket.

Parameters
bufferAn array of type xtd::byte that contains the data to send.
offsetThe zero-based position in the buffer parameter at which to begin sending data.
sizeThe number of bytes to send.
socket_flagsA bitwise combination of the xtd::net::sockets::socket_flags values.
callbackThe xtd::async_callback delegate.
stateAn object that contains state information for this request.
Returns
An xtd::iasync_result that references the asynchronous connection.
Exceptions
xtd::argument_out_of_range_exceptionsize is less than 0 or exceeds the size of the buffer.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
xtd::invalid_operation_exceptionThe accepting socket is not listening for connections. You must call xtd::net::sockets::socket::bind and xtd::net::sockets::socket::listen before calling xtd::net::sockets::socket::accept().
Remarks
The xtd::net::sockets::socket::begin_send method starts an asynchronous send operation to the remote host established in the xtd::net::sockets::socket::connect, xtd::net::sockets::socket::begin_connect, xtd::net::sockets::socket::accept, or xtd::net::sockets::socket::begin_accept method. xtd::net::sockets::socket::begin_send will throw an exception if you do not first call xtd::net::sockets::socket::accept, xtd::net::sockets::socket::begin_accept, xtd::net::sockets::socket::connect, or xtd::net::sockets::socket::begin_connect. Calling the xtd::net::sockets::socket::begin_send method gives you the ability to send data within a separate execution thread.
You can create a callback method that implements the xtd::async_callback delegate and pass its name to the xtd::net::sockets::socket::begin_send method. To do this, at the very minimum, your state parameter must contain the connected or default xtd::net::sockets::socket::socket being used for communication. If your callback needs more information, you can create a small class or structure to hold the xtd::net::sockets::socket::socket and the other required information. Pass an instance of this class to the xtd::net::sockets::socket::begin_send method through the state parameter.
Your callback method should invoke the xtd::net::sockets::socket::end_send method. When your application calls xtd::net::sockets::socket::begin_send, the system will use a separate thread to execute the specified callback method, and will block on xtd::net::sockets::socket::end_send until the xtd::net::sockets::socket::socket sends the number of bytes requested or throws an exception. If you want the original thread to block after you call the xtd::net::sockets::socket::begin_send method, use the xtd::threading::mutex::wait_one method. Call the xtd::threading::mutex::release_mutex method on a xtd::threading::mutex in the callback method when you want the original thread to continue executing.
Although intended for connection-oriented protocols, xtd::net::sockets::socket::begin_send also works for connectionless protocols, provided that you first call the xtd::net::sockets::socket::connect or xtd::net::sockets::socket::begin_connect method to establish a default remote host. If you are using a connectionless protocol and plan to send data to several different hosts, you should use xtd::net::sockets::socket::begin_send_to. It is okay to use xtd::net::sockets::socket::begin_send_to even after you have established a default remote host with xtd::net::sockets::socket::connect. You can also change the default remote host prior to calling xtd::net::sockets::socket::begin_send by making another call to xtd::net::sockets::socket::connect or xtd::net::sockets::socket::begin_connect. With connectionless protocols, you must also be sure that the size of your buffer does not exceed the maximum packet size of the underlying service provider. If it does, the datagram will not be sent and xtd::net::sockets::socket::begin_send will throw a xtd::net::sockets::socket_exception.
If you specify the xtd::net::sockets::socket_flags::dont_route flag as the socketflags parameter, the data you are sending will not be routed.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.
All I/O initiated by a given thread is canceled when that thread exits. A pending asynchronous operation can fail if the thread exits before the operation completes.
state is an instantiation of a user-defined class.
The successful completion of a send does not indicate that the data was successfully delivered. If no buffer space is available within the transport system to hold the data to be transmitted, send will block unless the socket has been placed in nonblocking mode.

◆ begin_send() [2/2]

xtd::sptr< xtd::iasync_result > xtd::net::sockets::socket::begin_send ( const std::vector< xtd::byte > &  buffer,
size_t  offset,
size_t  size,
xtd::net::sockets::socket_flags  socket_flags,
xtd::net::sockets::socket_error error_code,
xtd::async_callback  callback,
const std::any &  state 
)

Sends data asynchronously to a connected xtd::net::sockets::socket::socket.

Parameters
bufferAn array of type xtd::byte that contains the data to send.
offsetThe zero-based position in the buffer parameter at which to begin sending data.
sizeThe number of bytes to send.
socket_flagsA bitwise combination of the xtd::net::sockets::socket_flags values.
error_codeA xtd::net::sockets::socket_error object that stores the socket error.
callbackThe xtd::async_callback delegate.
stateAn object that contains state information for this request.
Returns
An xtd::iasync_result that references the asynchronous connection.
Exceptions
xtd::argument_out_of_range_exceptionsize is less than 0 or exceeds the size of the buffer.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
xtd::invalid_operation_exceptionThe accepting socket is not listening for connections. You must call xtd::net::sockets::socket::bind and xtd::net::sockets::socket::listen before calling xtd::net::sockets::socket::accept().
Remarks
The xtd::net::sockets::socket::begin_send method starts an asynchronous send operation to the remote host established in the xtd::net::sockets::socket::connect, xtd::net::sockets::socket::begin_connect, xtd::net::sockets::socket::accept, or xtd::net::sockets::socket::begin_accept method. xtd::net::sockets::socket::begin_send will throw an exception if you do not first call xtd::net::sockets::socket::accept, xtd::net::sockets::socket::begin_accept, xtd::net::sockets::socket::connect, or xtd::net::sockets::socket::begin_connect. Calling the xtd::net::sockets::socket::begin_send method gives you the ability to send data within a separate execution thread.
You can create a callback method that implements the xtd::async_callback delegate and pass its name to the xtd::net::sockets::socket::begin_send method. To do this, at the very minimum, your state parameter must contain the connected or default xtd::net::sockets::socket::socket being used for communication. If your callback needs more information, you can create a small class or structure to hold the xtd::net::sockets::socket::socket and the other required information. Pass an instance of this class to the xtd::net::sockets::socket::begin_send method through the state parameter.
Your callback method should invoke the xtd::net::sockets::socket::end_send method. When your application calls xtd::net::sockets::socket::begin_send, the system will use a separate thread to execute the specified callback method, and will block on xtd::net::sockets::socket::end_send until the xtd::net::sockets::socket::socket sends the number of bytes requested or throws an exception. If you want the original thread to block after you call the xtd::net::sockets::socket::begin_send method, use the xtd::threading::mutex::wait_one method. Call the xtd::threading::mutex::release_mutex method on a xtd::threading::mutex in the callback method when you want the original thread to continue executing.
Although intended for connection-oriented protocols, xtd::net::sockets::socket::begin_send also works for connectionless protocols, provided that you first call the xtd::net::sockets::socket::connect or xtd::net::sockets::socket::begin_connect method to establish a default remote host. If you are using a connectionless protocol and plan to send data to several different hosts, you should use xtd::net::sockets::socket::begin_send_to. It is okay to use xtd::net::sockets::socket::begin_send_to even after you have established a default remote host with xtd::net::sockets::socket::connect. You can also change the default remote host prior to calling xtd::net::sockets::socket::begin_send by making another call to xtd::net::sockets::socket::connect or xtd::net::sockets::socket::begin_connect. With connectionless protocols, you must also be sure that the size of your buffer does not exceed the maximum packet size of the underlying service provider. If it does, the datagram will not be sent and xtd::net::sockets::socket::begin_send will throw a xtd::net::sockets::socket_exception.
If you specify the xtd::net::sockets::socket_flags::dont_route flag as the socketflags parameter, the data you are sending will not be routed.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.
All I/O initiated by a given thread is canceled when that thread exits. A pending asynchronous operation can fail if the thread exits before the operation completes.
state is an instantiation of a user-defined class.
The successful completion of a send does not indicate that the data was successfully delivered. If no buffer space is available within the transport system to hold the data to be transmitted, send will block unless the socket has been placed in nonblocking mode.

◆ begin_send_to()

xtd::sptr< xtd::iasync_result > xtd::net::sockets::socket::begin_send_to ( const std::vector< xtd::byte > &  buffer,
size_t  offset,
size_t  size,
xtd::net::sockets::socket_flags  socket_flags,
const xtd::net::end_point remote_end_point,
xtd::async_callback  callback,
const std::any &  state 
)

Sends data asynchronously to a specific remote host.

Parameters
bufferAn array of type xtd::byte that contains the data to send.
offsetThe zero-based position in buffer at which to begin sending data.
sizeThe number of bytes to send.
socket_flagsA bitwise combination of the xtd::net::sockets::socket_flags values.
remote_end_pointAn xtd::net::end_point that represents the remote device.
callbackThe xtd::async_callback delegate.
stateAn object that contains state information for this request.
Returns
An xtd::iasync_result that references the asynchronous connection.
Exceptions
xtd::argument_out_of_range_exceptionsize is less than 0 or exceeds the size of the buffer.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
xtd::invalid_operation_exceptionThe accepting socket is not listening for connections. You must call xtd::net::sockets::socket::bind and xtd::net::sockets::socket::listen before calling xtd::net::sockets::socket::accept().
Remarks
The xtd::net::sockets::socket::begin_send_to method starts an asynchronous send operation to the remote host specified in the remote_end_point parameter. Calling the xtd::net::sockets::socket::begin_send_to method gives you the ability to send data within a separate execution thread. Although intended for connectionless protocols, xtd::net::sockets::socket::begin_send_to works with both connectionless and connection-oriented protocols.
You can create a callback method that implements the xtd::async_callback delegate and pass its name to the xtd::net::sockets::socket::begin_send_to method. To do this, at the very minimum, your state parameter must contain the connected or default xtd::net::sockets::socket::socket being used for communication. If your callback needs more information, you can create a small class to hold the xtd::net::sockets::socket::socket, and the other required information. Pass an instance of this class to the xtd::net::sockets::socket::begin_send_to method through the state parameter.
Your callback method should invoke the xtd::net::sockets::socket::end_send_to method. When your application calls xtd::net::sockets::socket::begin_send_to, the system will use a separate thread to execute the specified callback method, and will block on xtd::net::sockets::socket::end_send_to until the xtd::net::sockets::socket::socket sends the number of bytes requested or throws an exception. If you want the original thread to block after you call the xtd::net::sockets::socket::begin_send_to method, use the xtd::threading::mutex::wait_one method. Call the xtd::threading::mutex::release_mutex method on a T:System.Threading.xtd::threading::mutex in the callback method when you want the original thread to continue executing. For additional information about writing callback methods see Marshaling a Delegate as a Callback Method.
If you are using a connection-oriented protocol, you must first call the xtd::net::sockets::socket::connect, xtd::net::sockets::socket::begin_connect, xtd::net::sockets::socket::accept, or xtd::net::sockets::socket::begin_accept method, or xtd::net::sockets::socket::begin_send_to will throw a xtd::net::sockets::socket_exception. xtd::net::sockets::socket::begin_send_to will ignore the remote_end_point parameter and send data to the xtd::net::end_point established in the xtd::net::sockets::socket::connect, xtd::net::sockets::socket::begin_connect, xtd::net::sockets::socket::accept, or xtd::net::sockets::socket::begin_accept method.
If you are using a connectionless protocol, you do not need to establish a default remote host with the xtd::net::sockets::socket::connect or xtd::net::sockets::socket::begin_connect method prior to calling xtd::net::sockets::socket::send_to. You only need to do this if you intend to call the xtd::net::sockets::socket::begin_send method. If you do call the xtd::net::sockets::socket::connect or xtd::net::sockets::socket::begin_connect method prior to calling xtd::net::sockets::socket::send_to, the remote_end_point parameter will override the specified default remote host for that send operation only. You are also not required to call the xtd::net::sockets::socket::bind method. In this case, the underlying service provider will assign the most appropriate local network address and port number. Use a port number of zero if you want the underlying service provider to select a free port. If you need to identify the assigned local network address and port number, you can use the xtd::net::sockets::socket::local_end_point property after the xtd::net::sockets::socket::end_send_to method successfully completes.
If you want to send data to a broadcast address, you must first call the xtd::net::sockets::socket::set_socket_option method and set the socket option to xtd::net::sockets::socket::socket_option_name::broadcast. -You must also be sure that the size of your buffer does not exceed the maximum packet size of the underlying service provider. If it does, the datagram will not be sent and xtd::net::sockets::socket::end_send_to will throw a xtd::net::sockets::socket_exception.
If you specify the xtd::net::sockets::socket_flags::dont_route flag as the socket_flags parameter, the data you are sending will not be routed.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ bind()

template<typename end_point_t >
void xtd::net::sockets::socket::bind ( const end_point_t &  local_end_point)
inline

Associates a xtd::net::sockets::socket with a local endpoint.

Parameters
localEndPointThe local xtd::net::sockets::end_point to associate with the xtd::net::sockets::socket.
Exceptions
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
Use the xtd::net::sockets::socket::bind method if you need to use a specific local endpoint. You must call xtd::net::sockets::socket::bind before you can call the xtd::net::sockets::socket::socket::listen method. You do not need to call xtd::net::sockets::socket::bind before using the xtd::net::sockets::socket::connect method unless you need to use a specific local endpoint. You can use the xtd::net::sockets::socket::bind method on both connectionless and connection-oriented protocols.
Before calling xtd::net::sockets::socket::bind, you must first create the local xtd::net::ip_end_point from which you intend to communicate data. If you do not care which local address is assigned, you can create an xtd::net::ip_end_point using xtd::net::ip_address::any as the address parameter, and the underlying service provider will assign the most appropriate network address. This might help simplify your application if you have multiple network interfaces. If you do not care which local port is used, you can create an xtd::net::ip_end_point using 0 for the port number. In this case, the service provider will assign an available port number between 1024 and 5000.
If you use the above approach, you can discover what local network address and port number has been assigned by calling the xtd::net::sockets::socket::local_dnd_point. If you are using a connection-oriented protocol, xtd::net::sockets::socket::local_end_point will not return the locally assigned network address until after you have made a call to the xtd::net::sockets::socket::connect or xtd::net::sockets::socket::end_connect method. If you are using a connectionless protocol, you will not have access to this information until you have completed a send or receive.
If a UDP socket wants to receive interface information on received packets, the xtd::net::sockets::socket::set_socket_option method should be explicitly called with the socket option set to xtd::net::sockets::socket_option_name::packet_information immediately after calling the xtd::net::sockets::socket::bind method.
Note
If you intend to receive multicast datagrams, you must call the xtd::net::sockets::socket::bind method with a multicast port number.
You must call the xtd::net::sockets::socket::bind method if you intend to receive connectionless datagrams using the xtd::net::sockets::socket::receive_from method.
If you receive a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.
Examples
network_stream.cpp, socket_tcp_ip_v4.cpp, socket_tcp_ip_v4_without_thread.cpp, socket_tcp_ip_v6.cpp, socket_udp_ip_v4.cpp, and socket_udp_ip_v6.cpp.

◆ close()

void xtd::net::sockets::socket::close ( )

Closes the xtd::net::sockets::socket connection and releases all associated resources.

Remarks
The xtd::net::sockets::socket::close method closes the remote host connection and releases all resources associated with the xtd::net::sockets::socket. Upon closing, the xtd::net::sockets::socket::connected property is set to false.
For connection-oriented protocols, it is recommended that you call xtd::net::sockets::socket::shutdown before calling the xtd::net::sockets::socket::close method. This ensures that all data is sent and received on the connected socket before it is closed.
If you need to call xtd::net::sockets::socket::close without first calling xtd::net::sockets::socket::shutdown, you can ensure that data queued for outgoing transmission will be sent by setting the xtd::net::sockets::socket::dont_linger xtd::net::sockets::socket option to false and specifying a non-zero time-out interval. xtd::net::sockets::socket::close will then block until this data is sent or until the specified time-out expires. If you set xtd::net::sockets::socket::dont_linger to false and specify a zero time-out interval, xtd::net::sockets::socket::close releases the connection and automatically discards outgoing queued data.
Note
To set the xtd::net::sockets::socket::dont_linger socket option to false, create a xtd::net::sockets::linger_option, set the xtd::net::sockets::linger_option::enabled property to true, and set the xtd::net::sockets::linger_option::linger_time property to the desired time out period. Use this xtd::net::sockets::linger_option along with the xtd::net::sockets::socket::dont_linger socket option to call the xtd::net::sockets::socket::set_socket_linger_option method.

◆ connect() [1/4]

template<typename end_point_t >
void xtd::net::sockets::socket::connect ( const end_point_t &  remote_end_point)
inline

Establishes a connection to a remote host.

Parameters
remote_end_pointAn xtd::net::end_point that represents the remote device.
Exceptions
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
If you are using a connection-oriented protocol such as TCP, the xtd::net::sockets::socket::connect method synchronously establishes a network connection between xtd::net::sockets::socket::local_end_point and the specified remote endpoint. If you are using a connectionless protocol, xtd::net::sockets::socket::connect establishes a default remote host. After you call xtd::net::sockets::socket::connect, you can send data to the remote device with the xtd::net::sockets::socket::send method, or receive data from the remote device with the xtd::net::sockets::socket::receive method.
If you are using a connectionless protocol such as UDP, you do not have to call xtd::net::sockets::socket::connect before sending and receiving data. You can use xtd::net::sockets::socket::send_to and xtd::net::sockets::socket::receive_from to synchronously communicate with a remote host. If you do call xtd::net::sockets::socket::connect, any datagrams that arrive from an address other than the specified default will be discarded. If you want to set your default remote host to a broadcast address, you must first call the xtd::net::sockets::socket::set_socket_option method and set the socket option to xtd::net::sockets::socket::socket_option_name::broadcast, or xtd::net::sockets::socket::connect will throw a xtd::net::sockets::socket_exception. If you receive a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation for a detailed description of the error.
The xtd::net::sockets::socket::connect method will block, unless you specifically set the xtd::net::sockets::socket::blocking property to false prior to calling xtd::net::sockets::socket::connect. If you are using a connection-oriented protocol like TCP and you do disable blocking, xtd::net::sockets::socket::connect will throw a xtd::net::sockets::socket_exception because it needs time to make the connection. Connectionless protocols will not throw an exception because they simply establish a default remote host. You can use xtd::net::sockets::socket_exception::error_code to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation for a detailed description of the error. If the error returned WSAEWOULDBLOCK, the remote host connection has been initiated by a connection-oriented xtd::net::sockets::socket, but has not yet completed successfully. Use the Poll method to determine when the xtd::net::sockets::socket is finished connecting.
Note
If you are using a connection-oriented protocol and did not call xtd::net::sockets::socket::bind before calling xtd::net::sockets::socket::connect, the underlying service provider will assign the local network address and port number. If you are using a connectionless protocol, the service provider will not assign a local network address and port number until you complete a send or receive operation. If you want to change the default remote host, call xtd::net::sockets::socket::connect again with the desired endpoint.
If the socket has been previously disconnected, then you cannot use this method to restore the connection. Use one of the asynchronous xtd::net::sockets::socket::begin_connect methods to reconnect. This is a limitation of the underlying provider.
Examples
socket_tcp_ip_v4.cpp, and socket_tcp_ip_v6.cpp.

◆ connect() [2/4]

void xtd::net::sockets::socket::connect ( const xtd::net::ip_address address,
uint16  port 
)

Establishes a connection to a remote host. The host is specified by an IP address and a port number.

Parameters
addressThe IP address of the remote host.
portThe port number of the remote host.
Exceptions
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
If you are using a connection-oriented protocol such as TCP, the xtd::net::sockets::socket::connect method synchronously establishes a network connection between xtd::net::sockets::socket::local_end_point and the specified remote endpoint. If you are using a connectionless protocol, xtd::net::sockets::socket::connect establishes a default remote host. After you call xtd::net::sockets::socket::connect, you can send data to the remote device with the xtd::net::sockets::socket::send method, or receive data from the remote device with the xtd::net::sockets::socket::receive method.
If you are using a connectionless protocol such as UDP, you do not have to call xtd::net::sockets::socket::connect before sending and receiving data. You can use xtd::net::sockets::socket::send_to and xtd::net::sockets::socket::receive_from to synchronously communicate with a remote host. If you do call xtd::net::sockets::socket::connect, any datagrams that arrive from an address other than the specified default will be discarded. If you want to set your default remote host to a broadcast address, you must first call the xtd::net::sockets::socket::set_socket_option method and set the socket option to xtd::net::sockets::socket::socket_option_name::broadcast, or xtd::net::sockets::socket::connect will throw a xtd::net::sockets::socket_exception. If you receive a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation for a detailed description of the error.
The xtd::net::sockets::socket::connect method will block, unless you specifically set the xtd::net::sockets::socket::blocking property to false prior to calling xtd::net::sockets::socket::connect. If you are using a connection-oriented protocol like TCP and you do disable blocking, xtd::net::sockets::socket::connect will throw a xtd::net::sockets::socket_exception because it needs time to make the connection. Connectionless protocols will not throw an exception because they simply establish a default remote host. You can use xtd::net::sockets::socket_exception::error_code to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation for a detailed description of the error. If the error returned WSAEWOULDBLOCK, the remote host connection has been initiated by a connection-oriented xtd::net::sockets::socket, but has not yet completed successfully. Use the Poll method to determine when the xtd::net::sockets::socket is finished connecting.
Note
If you are using a connection-oriented protocol and did not call xtd::net::sockets::socket::bind before calling xtd::net::sockets::socket::connect, the underlying service provider will assign the local network address and port number. If you are using a connectionless protocol, the service provider will not assign a local network address and port number until you complete a send or receive operation. If you want to change the default remote host, call xtd::net::sockets::socket::connect again with the desired endpoint.
If the socket has been previously disconnected, then you cannot use this method to restore the connection. Use one of the asynchronous xtd::net::sockets::socket::begin_connect methods to reconnect. This is a limitation of the underlying provider.

◆ connect() [3/4]

void xtd::net::sockets::socket::connect ( const std::vector< xtd::net::ip_address > &  addresses,
uint16  port 
)

Establishes a connection to a remote host. The host is specified by an array of IP addresses and a port number.

Parameters
addressesThe IP addresses of the remote host.
portThe port number of the remote host.
Exceptions
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
This method is typically used immediately after a call to xtd::net::dns::get_host_addresses, which can return multiple IP addresses for a single host. If you are using a connection-oriented protocol such as TCP, the xtd::net::sockets::socket::connect method synchronously establishes a network connection between xtd::net::sockets::socket::local_end_point and the specified remote endpoint. If you are using a connectionless protocol, xtd::net::sockets::socket::connect establishes a default remote host. After you call xtd::net::sockets::socket::connect you can send data to the remote device with the xtd::net::sockets::socket::send method, or receive data from the remote device with the xtd::net::sockets::socket::receive method.
If you are using a connection-oriented protocol such as TCP, the xtd::net::sockets::socket::connect method synchronously establishes a network connection between xtd::net::sockets::socket::local_end_point and the specified remote endpoint. If you are using a connectionless protocol, xtd::net::sockets::socket::connect establishes a default remote host. After you call xtd::net::sockets::socket::connect, you can send data to the remote device with the xtd::net::sockets::socket::send method, or receive data from the remote device with the xtd::net::sockets::socket::receive method.
If you are using a connectionless protocol such as UDP, you do not have to call xtd::net::sockets::socket::connect before sending and receiving data. You can use xtd::net::sockets::socket::send_to and xtd::net::sockets::socket::receive_from to synchronously communicate with a remote host. If you do call xtd::net::sockets::socket::connect, any datagrams that arrive from an address other than the specified default will be discarded. If you want to set your default remote host to a broadcast address, you must first call the xtd::net::sockets::socket::set_socket_option method and set the socket option to xtd::net::sockets::socket::socket_option_name::broadcast, or xtd::net::sockets::socket::connect will throw a xtd::net::sockets::socket_exception. If you receive a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation for a detailed description of the error.
The xtd::net::sockets::socket::connect method will block, unless you specifically set the xtd::net::sockets::socket::blocking property to false prior to calling xtd::net::sockets::socket::connect. If you are using a connection-oriented protocol like TCP and you do disable blocking, xtd::net::sockets::socket::connect will throw a xtd::net::sockets::socket_exception because it needs time to make the connection. Connectionless protocols will not throw an exception because they simply establish a default remote host. You can use xtd::net::sockets::socket_exception::error_code to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation for a detailed description of the error. If the error returned WSAEWOULDBLOCK, the remote host connection has been initiated by a connection-oriented xtd::net::sockets::socket, but has not yet completed successfully. Use the Poll method to determine when the xtd::net::sockets::socket is finished connecting.
Note
If you are using a connection-oriented protocol and did not call xtd::net::sockets::socket::bind before calling xtd::net::sockets::socket::connect, the underlying service provider will assign the local network address and port number. If you are using a connectionless protocol, the service provider will not assign a local network address and port number until you complete a send or receive operation. If you want to change the default remote host, call xtd::net::sockets::socket::connect again with the desired endpoint.
If the socket has been previously disconnected, then you cannot use this method to restore the connection. Use one of the asynchronous xtd::net::sockets::socket::begin_connect methods to reconnect. This is a limitation of the underlying provider.

◆ connect() [4/4]

void xtd::net::sockets::socket::connect ( const xtd::string host,
uint16  port 
)

Establishes a connection to a remote host. The host is specified by a host name and a port number.

Parameters
hostThe name of the remote host.
portThe port number of the remote host.
Exceptions
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
If you are using a connection-oriented protocol such as TCP, the xtd::net::sockets::socket::connect method synchronously establishes a network connection between xtd::net::sockets::socket::local_end_point and the specified remote endpoint. If you are using a connectionless protocol, xtd::net::sockets::socket::connect establishes a default remote host. After you call xtd::net::sockets::socket::connect, you can send data to the remote device with the xtd::net::sockets::socket::send method, or receive data from the remote device with the xtd::net::sockets::socket::receive method.
If you are using a connectionless protocol such as UDP, you do not have to call xtd::net::sockets::socket::connect before sending and receiving data. You can use xtd::net::sockets::socket::send_to and xtd::net::sockets::socket::receive_from to synchronously communicate with a remote host. If you do call xtd::net::sockets::socket::connect, any datagrams that arrive from an address other than the specified default will be discarded. If you want to set your default remote host to a broadcast address, you must first call the xtd::net::sockets::socket::set_socket_option method and set the socket option to xtd::net::sockets::socket::socket_option_name::broadcast, or xtd::net::sockets::socket::connect will throw a xtd::net::sockets::socket_exception. If you receive a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation for a detailed description of the error.
The xtd::net::sockets::socket::connect method will block, unless you specifically set the xtd::net::sockets::socket::blocking property to false prior to calling xtd::net::sockets::socket::connect. If you are using a connection-oriented protocol like TCP and you do disable blocking, xtd::net::sockets::socket::connect will throw a xtd::net::sockets::socket_exception because it needs time to make the connection. Connectionless protocols will not throw an exception because they simply establish a default remote host. You can use xtd::net::sockets::socket_exception::error_code to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation for a detailed description of the error. If the error returned WSAEWOULDBLOCK, the remote host connection has been initiated by a connection-oriented xtd::net::sockets::socket, but has not yet completed successfully. Use the Poll method to determine when the xtd::net::sockets::socket is finished connecting.
Note
If you are using a connection-oriented protocol and did not call xtd::net::sockets::socket::bind before calling xtd::net::sockets::socket::connect, the underlying service provider will assign the local network address and port number. If you are using a connectionless protocol, the service provider will not assign a local network address and port number until you complete a send or receive operation. If you want to change the default remote host, call xtd::net::sockets::socket::connect again with the desired endpoint.
If the socket has been previously disconnected, then you cannot use this method to restore the connection. Use one of the asynchronous xtd::net::sockets::socket::begin_connect methods to reconnect. This is a limitation of the underlying provider.

◆ disconnect()

void xtd::net::sockets::socket::disconnect ( bool  reuse_socket)

Closes the socket connection and allows reuse of the socket.

Parameters
reuse_sockettrue if this socket can be reused after the current connection is closed; otherwise, false.
Exceptions
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
If you are using a connection-oriented protocol, you can use this method to close the socket. This method ends the connection and sets the xtd::net::sockets::socket::connected property to false. However, if reuseSocket is true, you can reuse the socket.
To ensure that all data is sent and received before the socket is closed, you should call xtd::net::sockets::socket::shutdown before calling the xtd::net::sockets::socket::disconnect method.
If you need to call xtd::net::sockets::socket::disconnect without first calling xtd::net::sockets::socket::shutdown, you can set the xtd::net::sockets::socket::dont_linger_socket option to false and specify a nonzero time-out interval to ensure that data queued for outgoing transmission is sent. xtd::net::sockets::socket::disconnect then blocks until the data is sent or until the specified time-out expires. If you set xtd::net::sockets::socket::dont_linger to false and specify a zero time-out interval, xtd::net::sockets::socket::close releases the connection and automatically discards outgoing queued data.
Note
If you receive a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ end_accept()

socket xtd::net::sockets::socket::end_accept ( xtd::sptr< xtd::iasync_result async_result)

Asynchronously accepts an incoming connection attempt and creates a new xtd::net::sockets::socket::socket to handle remote host communication.

Parameters
async_resultAn xtd::iasync_result that stores state information for this asynchronous operation as well as any user defined data.
Returns
A xtd::net::sockets::socket::socket to handle communication with the remote host.
Exceptions
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
xtd::net::sockets::socket::end_accept completes a call to xtd::net::sockets::socket::begin_accept. Before calling xtd::net::sockets::socket::begin_accept, you need to create a callback method that implements the xtd::async_callback delegate. This callback method executes in a separate thread, and is called by the system after the xtd::net::sockets::socket::begin_accept method returns. It must accept the asyncResult parameter returned from the xtd::net::sockets::socket::begin_accept method.
Within the callback method, call the xtd::iasync_result::async_state method of the asyncResult parameter to obtain the xtd::net::sockets::socket::socket on which the connection attempt is being made. After obtaining the xtd::net::sockets::socket::socket, you can call the xtd::net::sockets::socket::end_accept method to successfully complete the connection attempt.
The xtd::net::sockets::socket::end_accept method blocks until a connection is pending in the incoming connection queue. The xtd::net::sockets::socket::end_accept method accepts the incoming connection and returns a new xtd::net::sockets::socket::socket that can be used to send data to and receive data from the remote host.
Note
If you receive a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.
Examples
socket_tcp_ip_v4_without_thread.cpp.

◆ end_connect()

void xtd::net::sockets::socket::end_connect ( xtd::sptr< xtd::iasync_result async_result)

Ends a pending asynchronous connection request.

Parameters
async_resultAn xtd::iasync_result that stores state information for this asynchronous operation as well as any user defined data.
Exceptions
argument_exceptionasyncResult was not returned by a call to the xtd::net::sockets::socket::begin_connect method.
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
xtd::net::sockets::socket::end_connect is a blocking method that completes the asynchronous remote host connection request started in the xtd::net::sockets::socket::begin_connect method.
Before calling xtd::net::sockets::socket::begin_connect, you need to create a callback method that implements the xtd::async_callback delegate. This callback method executes in a separate thread and is called by the system after xtd::net::sockets::socket::begin_connect returns. The callback method must accept the xtd::iasync_result returned by the xtd::net::sockets::socket::begin_connect method as a parameter.
Within the callback method, call the xtd::iasync_result::async_state method of the xtd::iasync_result parameter to obtain the xtd::net::sockets::socket::socket on which the connection attempt is being made. After obtaining the xtd::net::sockets::socket::socket, you can call the xtd::net::sockets::socket::end_connect method to successfully complete the connection attempt.
Note
If you receive a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.
Examples
socket_tcp_ip_v4_without_thread.cpp.

◆ end_disconnect()

void xtd::net::sockets::socket::end_disconnect ( xtd::sptr< xtd::iasync_result async_result)

Ends a pending asynchronous disconnect request.

Parameters
async_resultAn xtd::iasync_result that stores state information for this asynchronous operation as well as any user defined data.
Exceptions
argument_exceptionasyncResult was not returned by a call to the xtd::net::sockets::socket::begin_disconnect method.
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
xtd::net::sockets::socket::end_disconnect completes a call to xtd::net::sockets::socket::begin_disconnect. The xtd::net::sockets::socket::end_disconnect method blocks until the disconnect completes. For information about asynchronous operations, see Asynchronous Programming Model (APM).
Note
If you receive a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ end_receive() [1/2]

size_t xtd::net::sockets::socket::end_receive ( xtd::sptr< xtd::iasync_result async_result)

Ends a pending asynchronous read.

Parameters
async_resultAn xtd::iasync_result that stores state information for this asynchronous operation as well as any user defined data.
Returns
The number of bytes received.
Exceptions
argument_exceptionasyncResult was not returned by a call to the xtd::net::sockets::socket::begin_receive method.
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
The xtd::net::sockets::socket::end_receive method completes the asynchronous read operation started in the xtd::net::sockets::socket::begin_receive method.
Before calling xtd::net::sockets::socket::begin_receive, you need to create a callback method that implements the xtd::async_callback delegate. This callback method executes in a separate thread and is called by the system after xtd::net::sockets::socket::begin_receive returns. The callback method must accept the xtd::iasync_result returned by the xtd::net::sockets::socket::begin_receive method as a parameter.
Within the callback method, call the xtd::iasync_result::async_state method of the xtd::iasync_result to obtain the state object passed to the xtd::net::sockets::socket::begin_receive method. Extract the receiving xtd::net::sockets::socket::socket from this state object. After obtaining the xtd::net::sockets::socket::socket, you can call the xtd::net::sockets::socket::end_receive method to successfully complete the read operation and return the number of bytes read.
The xtd::net::sockets::socket::end_receive method will block until data is available. If you are using a connectionless protocol, xtd::net::sockets::socket::end_receive will read the first enqueued datagram available in the incoming network buffer. If you are using a connection-oriented protocol, the xtd::net::sockets::socket::end_receive method will read as much data as is available up to the number of bytes you specified in the size parameter of the xtd::net::sockets::socket::begin_receive method. If the remote host shuts down the xtd::net::sockets::socket::socket connection with the Shutdown method, and all available data has been received, the xtd::net::sockets::socket::end_receive method will complete immediately and return zero bytes.
To obtain the received data, call the xtd::iasync_result::async_state method of the xtd::iasync_result, and extract the buffer contained in the resulting state object.
To cancel a pending xtd::net::sockets::socket::begin_receive, call the xtd::net::sockets::socket::socket::close method.
Note
If you receive a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.
All I/O initiated by a given thread is canceled when that thread exits. A pending asynchronous operation can fail if the thread exits before the operation completes.

◆ end_receive() [2/2]

size_t xtd::net::sockets::socket::end_receive ( xtd::sptr< xtd::iasync_result async_result,
xtd::net::sockets::socket_error error_code 
)

Ends a pending asynchronous read.

Parameters
async_resultAn xtd::iasync_result that stores state information for this asynchronous operation as well as any user defined data.
error_codeA xtd::net::sockets::socket_error object that stores the socket error.
Returns
The number of bytes received.
Exceptions
argument_exceptionasyncResult was not returned by a call to the xtd::net::sockets::socket::begin_receive method.
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
The xtd::net::sockets::socket::end_receive method completes the asynchronous read operation started in the xtd::net::sockets::socket::begin_receive method.
Before calling xtd::net::sockets::socket::begin_receive, you need to create a callback method that implements the xtd::async_callback delegate. This callback method executes in a separate thread and is called by the system after xtd::net::sockets::socket::begin_receive returns. The callback method must accept the xtd::iasync_result returned by the xtd::net::sockets::socket::begin_receive method as a parameter.
Within the callback method, call the xtd::iasync_result::async_state method of the xtd::iasync_result to obtain the state object passed to the xtd::net::sockets::socket::begin_receive method. Extract the receiving xtd::net::sockets::socket::socket from this state object. After obtaining the xtd::net::sockets::socket::socket, you can call the xtd::net::sockets::socket::end_receive method to successfully complete the read operation and return the number of bytes read.
The xtd::net::sockets::socket::end_receive method will block until data is available. If you are using a connectionless protocol, xtd::net::sockets::socket::end_receive will read the first enqueued datagram available in the incoming network buffer. If you are using a connection-oriented protocol, the xtd::net::sockets::socket::end_receive method will read as much data as is available up to the number of bytes you specified in the size parameter of the xtd::net::sockets::socket::begin_receive method. If the remote host shuts down the xtd::net::sockets::socket::socket connection with the Shutdown method, and all available data has been received, the xtd::net::sockets::socket::end_receive method will complete immediately and return zero bytes.
To obtain the received data, call the xtd::iasync_result::async_state method of the xtd::iasync_result, and extract the buffer contained in the resulting state object.
Note
If you receive a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.
All I/O initiated by a given thread is canceled when that thread exits. A pending asynchronous operation can fail if the thread exits before the operation completes.

◆ end_receive_from()

size_t xtd::net::sockets::socket::end_receive_from ( xtd::sptr< xtd::iasync_result async_result,
xtd::sptr< xtd::net::end_point > &  end_point 
)

Ends a pending asynchronous read from a specific endpoint.

Parameters
async_resultAn xtd::iasync_result that stores state information for this asynchronous operation as well as any user defined data.
end_pointThe source xtd::net::end_point.
Exceptions
argument_exceptionasyncResult was not returned by a call to the xtd::net::sockets::socket::begin_receive_from method.
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
The xtd::net::sockets::socket::end_receive_from method completes the asynchronous read operation started in the xtd::net::sockets::socket::begin_receive_from method.
Before calling xtd::net::sockets::socket::begin_receive_from, you need to create a callback method that implements the xtd::async_callback delegate. This callback method executes in a separate thread and is called by the system after xtd::net::sockets::socket::begin_receive_from returns. The callback method must accept the xtd::iasync_result returned by the xtd::net::sockets::socket::begin_receive_from method as a parameter.
Within the callback method, call the xtd::iasync_result::async_state method of the xtd::iasync_result to obtain the state object passed to the xtd::net::sockets::socket::begin_receive_from method. Extract the receiving xtd::net::sockets::socket::socket from this state object. After obtaining the xtd::net::sockets::socket::socket, you can call the xtd::net::sockets::socket::end_receive_from method to successfully complete the read operation and return the number of bytes read.
The xtd::net::sockets::socket::end_receive_from method will block until data is available. If you are using a connectionless protocol, xtd::net::sockets::socket::end_receive_from will read the first enqueued datagram available in the incoming network buffer. If you are using a connection-oriented protocol, the xtd::net::sockets::socket::end_receive_from method will read as much data as is available up to the number of bytes you specified in the size parameter of the xtd::net::sockets::socket::begin_receive_from method. If the remote host shuts down the xtd::net::sockets::socket::socket connection with the Shutdown method, and all available data has been received, the xtd::net::sockets::socket::end_receive_from method will complete immediately and return zero bytes. To obtain the received data, call the xtd::iasync_result::async_state method of the xtd::iasync_result object, and extract the buffer contained in the resulting state object. To identify the originating host, extract the xtd::net::end_point and cast it to an IPEndPoint. Use the IPEndPoint.Address method to obtain the IP address and the IPEndPoint.Port method to obtain the port number.
Note
If you receive a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ end_receive_message_from()

size_t xtd::net::sockets::socket::end_receive_message_from ( xtd::sptr< xtd::iasync_result async_result,
xtd::net::sockets::socket_flags socket_flags,
xtd::sptr< xtd::net::end_point > &  end_point,
xtd::net::sockets::ip_packet_information ip_packet_information 
)

Ends a pending asynchronous read from a specific endpoint. This method also reveals more information about the packet than xtd::net::sockets::socket::end_receive_from(xtd::iasync_result, xtd::net::end_point).

Parameters
async_resultAn xtd::iasync_result that stores state information for this asynchronous operation as well as any user defined data.
socket_flagsA bitwise combination of the xtd::net::sockets::socket_flags values for the received packet.
end_pointThe source xtd::net::end_point.
ip_packet_informationThe xtd::net::ip_address and interface of the received packet.
Returns
If successful, the number of bytes received. If unsuccessful, returns 0.
Exceptions
argument_exceptionasyncResult was not returned by a call to the xtd::net::sockets::socket::begin_receive_message_from method.
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
If the operation has not completed, this method blocks until it does.
To perform this operation synchronously, use the xtd::net::sockets::socket::receive_message_from method.
Examine ipPacketInformation if you need to know if the datagram was sent using a unicast, multicast, or broadcast address.
Note
If you receive a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ end_send() [1/2]

size_t xtd::net::sockets::socket::end_send ( xtd::sptr< xtd::iasync_result async_result)

Ends a pending asynchronous send.

Parameters
async_resultAn xtd::iasync_result that stores state information for this asynchronous operation as well as any user defined data.
Returns
If successful, the number of bytes sent to the xtd::net::sockets::socket::socket; otherwise, an invalid xtd::net::sockets::socket::socket error.
Exceptions
argument_exceptionasyncResult was not returned by a call to the xtd::net::sockets::socket::begin_send method.
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
xtd::net::sockets::socket::end_send completes the asynchronous send operation started in xtd::net::sockets::socket::begin_send.
Before calling xtd::net::sockets::socket::begin_send, you need to create a callback method that implements the xtd::async_callback delegate. This callback method executes in a separate thread and is called by the system after xtd::net::sockets::socket::begin_send returns. The callback method must accept the xtd::iasync_result returned by the xtd::net::sockets::socket::begin_send method as a parameter.
Within the callback method, call the xtd::iasync_result::async_state method of the xtd::iasync_result parameter to obtain the sending xtd::net::sockets::socket::socket. After obtaining the xtd::net::sockets::socket::socket, you can call the xtd::net::sockets::socket::end_send method to successfully complete the send operation and return the number of bytes sent.
If you are using a connectionless protocol, xtd::net::sockets::socket::end_send will block until the datagram is sent. If you are using a connection-oriented protocol, xtd::net::sockets::socket::end_send will block until some of the buffer was sent. If the return value from xtd::net::sockets::socket::end_send indicates that the buffer was not completely sent, call the xtd::net::sockets::socket::begin_send method again, modifying the buffer to hold the unsent data.
There is no guarantee that the data you send will appear on the network immediately. To increase network efficiency, the underlying system may delay transmission until a significant amount of outgoing data is collected. A successful completion of the xtd::net::sockets::socket::begin_send method means that the underlying system has had room to buffer your data for a network send.
Note
If you receive a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.
All I/O initiated by a given thread is canceled when that thread exits. A pending asynchronous operation can fail if the thread exits before the operation completes.
The successful completion of a send does not indicate that the data was successfully delivered. If no buffer space is available within the transport system to hold the data to be transmitted, send will block unless the socket has been placed in nonblocking mode.

◆ end_send() [2/2]

size_t xtd::net::sockets::socket::end_send ( xtd::sptr< xtd::iasync_result async_result,
xtd::net::sockets::socket_error error_code 
)

Ends a pending asynchronous send.

Parameters
async_resultAn xtd::iasync_result that stores state information for this asynchronous operation as well as any user defined data.
error_codeA xtd::net::sockets::socket_error object that stores the socket error.
Returns
If successful, the number of bytes sent to the xtd::net::sockets::socket::socket; otherwise, an invalid xtd::net::sockets::socket::socket error.
Exceptions
argument_exceptionasyncResult was not returned by a call to the xtd::net::sockets::socket::begin_send method.
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
xtd::net::sockets::socket::end_send completes the asynchronous send operation started in xtd::net::sockets::socket::begin_send.
Before calling xtd::net::sockets::socket::begin_send, you need to create a callback method that implements the xtd::async_callback delegate. This callback method executes in a separate thread and is called by the system after xtd::net::sockets::socket::begin_send returns. The callback method must accept the xtd::iasync_result returned by the xtd::net::sockets::socket::begin_send method as a parameter.
Within the callback method, call the xtd::iasync_result::async_state method of the xtd::iasync_result parameter to obtain the sending xtd::net::sockets::socket::socket. After obtaining the xtd::net::sockets::socket::socket, you can call the xtd::net::sockets::socket::end_send method to successfully complete the send operation and return the number of bytes sent.
If you are using a connectionless protocol, xtd::net::sockets::socket::end_send will block until the datagram is sent. If you are using a connection-oriented protocol, xtd::net::sockets::socket::end_send will block until some of the buffer was sent. If the return value from xtd::net::sockets::socket::end_send indicates that the buffer was not completely sent, call the xtd::net::sockets::socket::begin_send method again, modifying the buffer to hold the unsent data.
There is no guarantee that the data you send will appear on the network immediately. To increase network efficiency, the underlying system may delay transmission until a significant amount of outgoing data is collected. A successful completion of the xtd::net::sockets::socket::begin_send method means that the underlying system has had room to buffer your data for a network send.
Note
If you receive a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.
All I/O initiated by a given thread is canceled when that thread exits. A pending asynchronous operation can fail if the thread exits before the operation completes.
The successful completion of a send does not indicate that the data was successfully delivered. If no buffer space is available within the transport system to hold the data to be transmitted, send will block unless the socket has been placed in nonblocking mode.

◆ end_send_to()

size_t xtd::net::sockets::socket::end_send_to ( xtd::sptr< xtd::iasync_result async_result)

Ends a pending asynchronous send to a specific location.

Parameters
async_resultAn xtd::iasync_result that stores state information for this asynchronous operation as well as any user defined data.
Returns
If successful, the number of bytes sent; otherwise, an invalid xtd::net::sockets::socket::socket error.
Exceptions
argument_exceptionasyncResult was not returned by a call to the xtd::net::sockets::socket::begin_send_to method.
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
xtd::net::sockets::socket::end_send_to completes the asynchronous send operation started in xtd::net::sockets::socket::begin_send_to.
Before calling xtd::net::sockets::socket::begin_send_to, you need to create a callback method that implements the xtd::async_callback delegate. This callback method executes in a separate thread and is called by the system after xtd::net::sockets::socket::begin_receive returns. The callback method must accept the xtd::iasync_result returned by the xtd::net::sockets::socket::begin_send_to method as a parameter.
Within the callback method, call the xtd::iasync_result::async_state method of the xtd::iasync_result parameter to obtain the sending xtd::net::sockets::socket::socket. After obtaining the xtd::net::sockets::socket::socket, you can call the xtd::net::sockets::socket::end_send_to method to successfully complete the send operation and return the number of bytes sent.
If you are using a connectionless protocol, xtd::net::sockets::socket::end_send_to will block until the datagram is sent. If you are using a connection-oriented protocol, xtd::net::sockets::socket::end_send_to will block until the requested number of bytes are sent. There is no guarantee that the data you send will appear on the network immediately. To increase network efficiency, the underlying system may delay transmission until a significant amount of outgoing data is collected. A successful completion of the xtd::net::sockets::socket::begin_send_to method means that the underlying system has had room to buffer your data for a network send.
Note
If you receive a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ get_raw_socket_option()

size_t xtd::net::sockets::socket::get_raw_socket_option ( int32  socket_option_level,
int32  socket_option_name,
intptr  option_value,
size_t  size_option_value 
) const

Gets a socket option value using platform-specific level and name identifiers.

Parameters
socket_option_levelThe platform-defined option level.
socket_option_nameThe platform-defined option name.
option_valueThe pointer into which the retrieved option value should be stored.
Returns
The number of bytes written into option_value for a successfully retrieved value.
Exceptions
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Note
If you receive a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation for a detailed description of the error.

◆ get_socket_option()

int32 xtd::net::sockets::socket::get_socket_option ( xtd::net::sockets::socket_option_level  socket_option_level,
xtd::net::sockets::socket_option_name  socket_option_name 
) const

Returns the value of a specified xtd::net::sockets::socket option, represented as integer.

Parameters
socket_option_levelOne of the xtd::net::sockets::socket_option_level values.
socket_option_nameOne of the xtd::net::sockets::socket_option_name values.
Returns
An object that represents the value of the option.
Exceptions
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
xtd::net::sockets::socket options determine the behavior of the current xtd::net::sockets::socket.
Use xtd::net::sockets::socket::get_socket_linger_option to get the xtd::net::sockets::socket_option_name::linger.
Use xtd::net::sockets::socket::get_socket_multicast_option xtd::net::sockets::socket_option_name::add_membership, and xtd::net::sockets::socket_option_name::xtd::net::sockets::socket_option_name::drop_membership xtd::net::sockets::socket options for IP v4 socket.
Use xtd::net::sockets::socket::get_socket_ip_v6__multicast_option xtd::net::sockets::socket_option_name::add_membership, and xtd::net::sockets::socket_option_name::xtd::net::sockets::socket_option_name::drop_membership xtd::net::sockets::socket options for IP v6 socket.
Note
If you receive a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation for a detailed description of the error.

◆ get_socket_linger_option()

xtd::net::sockets::linger_option xtd::net::sockets::socket::get_socket_linger_option ( ) const

Returns the linger xtd::net::sockets::socket option, represented as xtd::net::sockets::linger_option.

Returns
An xtd::net::sockets::linger_option that represents the value of the linger option.
Exceptions
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
xtd::net::sockets::socket options determine the behavior of the current xtd::net::sockets::socket. Use this overload to get the xtd::net::sockets::socket_option_name::linger, xtd::net::sockets::socket_option_name::add_membership, and xtd::net::sockets::socket_option_name::xtd::net::sockets::socket_option_name::drop_membership xtd::net::sockets::socket options. For the xtd::net::sockets::socket_option_name::linger option, use xtd::net::sockets::socket_option_level::socket for the option_level parameter. For xtd::net::sockets::socket_option_name::add_membership and xtd::net::sockets::socket_option_name::drop_membership, use xtd::net::sockets::socket_option_level::ip. If you want to set the value of any of the options listed above, use the xtd::net::sockets::socket_option_name::xtd::net::sockets::socket::set_socket_option method.
Note
If you receive a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation for a detailed description of the error.

◆ get_socket_multicast_option()

xtd::net::sockets::multicast_option xtd::net::sockets::socket::get_socket_multicast_option ( xtd::net::sockets::socket_option_name  socket_option_name) const

Returns the multicast xtd::net::sockets::socket option, represented as xtd::net::sockets::multicast_option.

Parameters
socket_option_nameOne of the xtd::net::sockets::socket_option_name values. Only xtd::net::sockets::socket_option_name::add_membership and xtd::net::sockets::socket_option_name::drop_membership values are accepted.
Returns
An xtd::net::sockets::linger_option that represents the value of the multicast option.
Exceptions
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Note
If you receive a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation for a detailed description of the error.

◆ get_socket_ip_v6_multicast_option()

xtd::net::sockets::ip_v6_multicast_option xtd::net::sockets::socket::get_socket_ip_v6_multicast_option ( xtd::net::sockets::socket_option_name  socket_option_name) const

Returns the multicast xtd::net::sockets::socket option, represented as xtd::net::sockets::ip_v6_multicast_option.

Parameters
socket_option_nameOne of the xtd::net::sockets::socket_option_name values. Only xtd::net::sockets::socket_option_name::add_membership and xtd::net::sockets::socket_option_name::drop_membership values are accepted.
Returns
An xtd::net::sockets::linger_option that represents the value of the multicast option.
Exceptions
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Note
If you receive a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation for a detailed description of the error.

◆ io_control() [1/2]

size_t xtd::net::sockets::socket::io_control ( int32  io_control_code,
std::vector< xtd::byte > &  option_in_value,
std::vector< xtd::byte > &  option_out_value 
)

Sets low-level operating modes for the xtd::net::sockets::socket using numerical control codes.

Parameters
io_control_codeAn int32 value that specifies the control code of the operation to perform.
option_in_valueA byte array that contains the input data required by the operation.
option_out_valueA byte array that contains the output data returned by the operation.
Returns
The number of bytes in the option_out_value parameter.
Remarks
The xtd::net::sockets::socket::io_control method provides low-level access to the operating system xtd::net::sockets::socket underlying the current instance of the xtd::net::sockets::socket class.
Note
If you receive a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation for a detailed description of the error.

◆ io_control() [2/2]

size_t xtd::net::sockets::socket::io_control ( xtd::net::sockets::io_control_code  io_control_code,
std::vector< xtd::byte > &  option_in_value,
std::vector< xtd::byte > &  option_out_value 
)

Sets low-level operating modes for the xtd::net::sockets::socket using xtd::net::sockets::io_control_code control codes.

Parameters
io_control_codeA xtd::net::sockets::io_control_code value that specifies the control code of the operation to perform.
option_in_valueA byte array that contains the input data required by the operation.
option_out_valueA byte array that contains the output data returned by the operation.
Returns
The number of bytes in the option_out_value parameter.
Remarks
The xtd::net::sockets::socket::io_control method provides low-level access to the operating system xtd::net::sockets::socket underlying the current instance of the xtd::net::sockets::socket class.
Note
If you receive a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation for a detailed description of the error.

◆ listen() [1/2]

void xtd::net::sockets::socket::listen ( size_t  backlog)

Places a xtd::net::sockets::socket in a listening state.

Parameters
backlogThe maximum length of the pending connections queue.
Exceptions
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
xtd::net::sockets::socket::listen causes a connection-oriented xtd::net::sockets::socket to listen for incoming connection attempts. The backlog parameter specifies the number of incoming connections that can be queued for acceptance. To determine the maximum number of connections you can specify, retrieve the xtd::net::sockets::socket_option_name::max_connections value. xtd::net::sockets::socket::listen does not block.
Note
If you receive a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation for a detailed description of the error.
You must call the xtd::net::sockets::socket::bind method before calling xtd::net::sockets::socket::listen, or xtd::net::sockets::socket::listen will throw a xtd::net::sockets::socket_exception.
The backlog parameter is limited to different values depending on the Operating System. You may specify a higher value, but the backlog will be limited based on the Operating System.

◆ listen() [2/2]

void xtd::net::sockets::socket::listen ( )

Places a xtd::net::sockets::socket in a listening state.

Exceptions
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
The maximum length of the pending connections queue is determined automatically.
xtd::net::sockets::socket::listen causes a connection-oriented xtd::net::sockets::socket to listen for incoming connection attempts. The backlog parameter specifies the number of incoming connections that can be queued for acceptance. To determine the maximum number of connections you can specify, retrieve the xtd::net::sockets::socket_option_name::max_connections value. xtd::net::sockets::socket::listen does not block.
Note
If you receive a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation for a detailed description of the error.
You must call the xtd::net::sockets::socket::bind method before calling xtd::net::sockets::socket::listen, or xtd::net::sockets::socket::listen will throw axed::net::sockets::socket_exception.
The backlog parameter is limited to different values depending on the Operating System. You may specify a higher value, but the backlog will be limited based on the Operating System.

◆ poll()

bool xtd::net::sockets::socket::poll ( int32  micro_seconds,
xtd::net::sockets::select_mode  mode 
)

Determines the status of the xtd::net::sockets::socket.

Parameters
micro_secondsThe time to wait for a response, in microseconds.
modeOne of the xtd::net::sockets::select_mode values.
Returns
The status of the xtd::net::sockets::socket based on the polling mode value passed in the mode parameter.
Mode Return Value
xtd::net::sockets::select_mode::select_read true if xtd::net::sockets::socket::listen has been called and a connection is pending;
-or-
true if data is available for reading;
-or-
true if the connection has been closed, reset, or terminated; otherwise, returns false.
xtd::net::sockets::select_mode::select_write true, if processing a xtd::net::sockets::socket::connect, and the connection has succeeded;
-or-
true if data can be sent; otherwise, returns false.
xtd::net::sockets::select_mode::select_error true if processing a xtd::net::sockets::socket::connect that does not block, and the connection has failed;
-or-
true if xtd::net::sockets::socket_option_name::out_of_band_inline is not set and out-of-band data is available; otherwise, returns false.
Exceptions
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
The xtd::net::sockets::socket::poll method checks the state of the xtd::net::sockets::socket. Specify xtd::net::sockets::select_mode::select_read for the select_mode parameter to determine if the xtd::net::sockets::socket is readable. Specify xtd::net::sockets::select_mode::select_write to determine if the xtd::net::sockets::socket is writable. Use SelectMode.SelectError to detect an error condition. Poll will block execution until the specified time period, measured in microseconds, elapses. Set the microSeconds parameter to a negative integer if you would like to wait indefinitely for a response. If you want to check the status of multiple sockets, you might prefer to use the xtd::net::sockets::socket::select method.
Note
If you receive a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation for a detailed description of the error.

◆ receive() [1/5]

size_t xtd::net::sockets::socket::receive ( std::vector< xtd::byte > &  buffer)

Receives data from a bound xtd::net::sockets::socket into a receive buffer.

Parameters
bufferAn array of type byte that is the storage location for the received data.
Returns
The number of bytes received.
Exceptions
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
The xtd::net::sockets::socket::receive method reads data into the buffer parameter and returns the number of bytes successfully read. You can call xtd::net::sockets::socket::receive from both connection-oriented and connectionless sockets.
This overload only requires you to provide a receive buffer. The buffer offset defaults to 0, the size defaults to the size of the buffer parameter, and the xtd::net::sockets::socket_flags value defaults to xtd::net::sockets::socket_flag::none.
If you are using a connection-oriented protocol, you must either call xtd::net::sockets::socket::connect to establish a remote host connection, or xtd::net::sockets::socket::accept to accept an incoming connection prior to calling xtd::net::sockets::socket::receive. The xtd::net::sockets::socket::receive method will only read data that arrives from the remote host established in the xtd::net::sockets::socket::connect or xtd::net::sockets::socket::accept method. If you are using a connectionless protocol, you can also use the xtd::net::sockets::socket::receive_from method. xtd::net::sockets::socket::receive_from will allow you to receive data arriving from any host.
If no data is available for reading, the xtd::net::sockets::socket::receive method will block until data is available, unless a time-out value was set by using xtd::net::sockets::socket::receive_timeout. If the time-out value was exceeded, the xtd::net::sockets::socket::receive call will throw a xtd::net::sockets::socket_exception. If you are in non-blocking mode, and there is no data available in the in the protocol stack buffer, the xtd::net::sockets::socket::receive method will complete immediately and throw a xtd::net::sockets::socket_exception. You can use the xtd::net::sockets::socket::available property to determine if data is available for reading. When xtd::net::sockets::socket::available is non-zero, retry the receive operation.
If you are using a connection-oriented xtd::net::sockets::socket, the xtd::net::sockets::socket::receive method will read as much data as is available, up to the size of the buffer. If the remote host shuts down the xtd::net::sockets::socket connection with the xtd::net::sockets::socket::shutdown method, and all available data has been received, the xtd::net::sockets::socket::receive method will complete immediately and return zero bytes.
If you are using a connectionless xtd::net::sockets::socket, xtd::net::sockets::socket::receive will read the first queued datagram from the destination address you specify in the xtd::net::sockets::socket::connect method. If the datagram you receive is larger than the size of the buffer parameter, buffer gets filled with the first part of the message, the excess data is lost and a xtd::net::sockets::socket::socket_exception is thrown.
Note
If you receive a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.
Examples
socket_tcp_ip_v4_without_thread.cpp.

◆ receive() [2/5]

size_t xtd::net::sockets::socket::receive ( std::vector< xtd::byte > &  buffer,
xtd::net::sockets::socket_flags  socket_flags 
)

Receives data from a bound xtd::net::sockets::socket into a receive buffer, using the specified xtd::net::sockets::socket_flags.

Parameters
bufferAn array of type byte that is the storage location for the received data.
socket_flagsA bitwise combination of the xtd::net::sockets::socket_flags values.
Returns
The number of bytes received.
Exceptions
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
The xtd::net::sockets::socket::receive method reads data into the buffer parameter and returns the number of bytes successfully read. You can call xtd::net::sockets::socket::receive from both connection-oriented and connectionless sockets.
This overload only requires you to provide a receive buffer and the necessary xtd::net::sockets::socket_flags. The buffer offset defaults to 0, and the size defaults to the length of the byte parameter.
If you are using a connection-oriented protocol, you must either call xtd::net::sockets::socket::connect to establish a remote host connection, or xtd::net::sockets::socket::accept to accept an incoming connection prior to calling xtd::net::sockets::socket::receive. The xtd::net::sockets::socket::receive method will only read data that arrives from the remote host established in the xtd::net::sockets::socket::connect or xtd::net::sockets::socket::accept method. If you are using a connectionless protocol, you can also use the xtd::net::sockets::socket::receive_from method. xtd::net::sockets::socket::receive_from will allow you to receive data arriving from any host.
If no data is available for reading, the xtd::net::sockets::socket::receive method will block until data is available, unless a time-out value was set by using xtd::net::sockets::socket::receive_timeout. If the time-out value was exceeded, the xtd::net::sockets::socket::receive call will throw a xtd::net::sockets::socket_exception. If you are in non-blocking mode, and there is no data available in the in the protocol stack buffer, the xtd::net::sockets::socket::receive method will complete immediately and throw a xtd::net::sockets::socket_exception. You can use the xtd::net::sockets::socket::available property to determine if data is available for reading. When xtd::net::sockets::socket::available is non-zero, retry the receive operation.
If you are using a connection-oriented xtd::net::sockets::socket, the xtd::net::sockets::socket::receive method will read as much data as is available, up to the size of the buffer. If the remote host shuts down the xtd::net::sockets::socket connection with the xtd::net::sockets::socket::shutdown method, and all available data has been received, the xtd::net::sockets::socket::receive method will complete immediately and return zero bytes.
If you are using a connectionless xtd::net::sockets::socket, xtd::net::sockets::socket::receive will read the first queued datagram from the destination address you specify in the xtd::net::sockets::socket::connect method. If the datagram you receive is larger than the size of the buffer parameter, buffer gets filled with the first part of the message, the excess data is lost and a xtd::net::sockets::socket::socket_exception is thrown.
Note
If you receive a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ receive() [3/5]

size_t xtd::net::sockets::socket::receive ( std::vector< xtd::byte > &  buffer,
size_t  size,
xtd::net::sockets::socket_flags  socket_flags 
)

Receives the specified number of bytes of data from a bound xtd::net::sockets::socket into a receive buffer, using the specified xtd::net::sockets::socket_flags.

Parameters
bufferAn array of type byte that is the storage location for the received data.
sizeThe number of bytes to receive.
socket_flagsA bitwise combination of the xtd::net::sockets::socket_flags values.
Returns
The number of bytes received.
Exceptions
xtd::argument_out_of_range_exceptionsize is less than 0 or exceeds the size of the buffer.
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
The xtd::net::sockets::socket::receive method reads data into the buffer parameter and returns the number of bytes successfully read. You can call xtd::net::sockets::socket::receive from both connection-oriented and connectionless sockets.
This overload only requires you to provide a receive buffer, the number of bytes you want to receive, and the necessary xtd::net::sockets::socket_flags.
If you are using a connection-oriented protocol, you must either call xtd::net::sockets::socket::connect to establish a remote host connection, or xtd::net::sockets::socket::accept to accept an incoming connection prior to calling xtd::net::sockets::socket::receive. The xtd::net::sockets::socket::receive method will only read data that arrives from the remote host established in the xtd::net::sockets::socket::connect or xtd::net::sockets::socket::accept method. If you are using a connectionless protocol, you can also use the xtd::net::sockets::socket::receive_from method. xtd::net::sockets::socket::receive_from will allow you to receive data arriving from any host.
If no data is available for reading, the xtd::net::sockets::socket::receive method will block until data is available, unless a time-out value was set by using xtd::net::sockets::socket::receive_timeout. If the time-out value was exceeded, the xtd::net::sockets::socket::receive call will throw a xtd::net::sockets::socket_exception. If you are in non-blocking mode, and there is no data available in the in the protocol stack buffer, the xtd::net::sockets::socket::receive method will complete immediately and throw a xtd::net::sockets::socket_exception. You can use the xtd::net::sockets::socket::available property to determine if data is available for reading. When xtd::net::sockets::socket::available is non-zero, retry the receive operation.
If you are using a connection-oriented xtd::net::sockets::socket, the xtd::net::sockets::socket::receive method will read as much data as is available, up to the size of the buffer. If the remote host shuts down the xtd::net::sockets::socket connection with the xtd::net::sockets::socket::shutdown method, and all available data has been received, the xtd::net::sockets::socket::receive method will complete immediately and return zero bytes.
If you are using a connectionless xtd::net::sockets::socket, xtd::net::sockets::socket::receive will read the first queued datagram from the destination address you specify in the xtd::net::sockets::socket::connect method. If the datagram you receive is larger than the size of the buffer parameter, buffer gets filled with the first part of the message, the excess data is lost and a xtd::net::sockets::socket::socket_exception is thrown.
Note
If you receive a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ receive() [4/5]

size_t xtd::net::sockets::socket::receive ( std::vector< xtd::byte > &  buffer,
size_t  offset,
size_t  size,
xtd::net::sockets::socket_flags  socket_flags 
)

Receives the specified number of bytes from a bound xtd::net::sockets::socket into the specified offset position of the receive buffer, using the specified xtd::net::sockets::socket_flags.

Parameters
bufferAn array of type byte that is the storage location for the received data.
offsetThe location in buffer to store the received data.
sizeThe number of bytes to receive.
socket_flagsA bitwise combination of the xtd::net::sockets::socket_flags values.
Returns
The number of bytes received.
Exceptions
xtd::argument_out_of_range_exceptionsize is less than 0 or exceeds the size of the buffer.
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
The xtd::net::sockets::socket::receive method reads data into the buffer parameter and returns the number of bytes successfully read. You can call xtd::net::sockets::socket::receive from both connection-oriented and connectionless sockets.
If you are using a connection-oriented protocol, you must either call xtd::net::sockets::socket::connect to establish a remote host connection, or xtd::net::sockets::socket::accept to accept an incoming connection prior to calling xtd::net::sockets::socket::receive. The xtd::net::sockets::socket::receive method will only read data that arrives from the remote host established in the xtd::net::sockets::socket::connect or xtd::net::sockets::socket::accept method. If you are using a connectionless protocol, you can also use the xtd::net::sockets::socket::receive_from method. xtd::net::sockets::socket::receive_from will allow you to receive data arriving from any host.
If no data is available for reading, the xtd::net::sockets::socket::receive method will block until data is available, unless a time-out value was set by using xtd::net::sockets::socket::receive_timeout. If the time-out value was exceeded, the xtd::net::sockets::socket::receive call will throw a xtd::net::sockets::socket_exception. If you are in non-blocking mode, and there is no data available in the in the protocol stack buffer, the xtd::net::sockets::socket::receive method will complete immediately and throw a xtd::net::sockets::socket_exception. You can use the xtd::net::sockets::socket::available property to determine if data is available for reading. When xtd::net::sockets::socket::available is non-zero, retry the receive operation.
If you are using a connection-oriented xtd::net::sockets::socket, the xtd::net::sockets::socket::receive method will read as much data as is available, up to the size of the buffer. If the remote host shuts down the xtd::net::sockets::socket connection with the xtd::net::sockets::socket::shutdown method, and all available data has been received, the xtd::net::sockets::socket::receive method will complete immediately and return zero bytes.
If you are using a connectionless xtd::net::sockets::socket, xtd::net::sockets::socket::receive will read the first queued datagram from the destination address you specify in the xtd::net::sockets::socket::connect method. If the datagram you receive is larger than the size of the buffer parameter, buffer gets filled with the first part of the message, the excess data is lost and a xtd::net::sockets::socket::socket_exception is thrown.
Note
If you receive a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ receive() [5/5]

size_t xtd::net::sockets::socket::receive ( std::vector< xtd::byte > &  buffer,
size_t  offset,
size_t  size,
xtd::net::sockets::socket_flags  socket_flags,
xtd::net::sockets::socket_error error 
)

Receives the specified number of bytes from a bound xtd::net::sockets::socket into the specified offset position of the receive buffer, using the specified xtd::net::sockets::socket_flags.

Parameters
bufferAn array of type byte that is the storage location for the received data.
offsetThe location in buffer to store the received data.
sizeThe number of bytes to receive.
socket_flagsA bitwise combination of the xtd::net::sockets::socket_flags values.
error_codeA xtd::net::sockets::socket_error object that stores the socket error.
Returns
The number of bytes received.
Exceptions
xtd::argument_out_of_range_exceptionsize is less than 0 or exceeds the size of the buffer.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
The xtd::net::sockets::socket::receive method reads data into the buffer parameter and returns the number of bytes successfully read. You can call xtd::net::sockets::socket::receive from both connection-oriented and connectionless sockets.
If you are using a connection-oriented protocol, you must either call xtd::net::sockets::socket::connect to establish a remote host connection, or xtd::net::sockets::socket::accept to accept an incoming connection prior to calling xtd::net::sockets::socket::receive. The xtd::net::sockets::socket::receive method will only read data that arrives from the remote host established in the xtd::net::sockets::socket::connect or xtd::net::sockets::socket::accept method. If you are using a connectionless protocol, you can also use the xtd::net::sockets::socket::receive_from method. xtd::net::sockets::socket::receive_from will allow you to receive data arriving from any host.
If no data is available for reading, the xtd::net::sockets::socket::receive method will block until data is available, unless a time-out value was set by using xtd::net::sockets::socket::receive_timeout. If the time-out value was exceeded, the xtd::net::sockets::socket::receive call will throw a xtd::net::sockets::socket_exception. If you are in non-blocking mode, and there is no data available in the in the protocol stack buffer, the xtd::net::sockets::socket::receive method will complete immediately and throw a xtd::net::sockets::socket_exception. You can use the xtd::net::sockets::socket::available property to determine if data is available for reading. When xtd::net::sockets::socket::available is non-zero, retry the receive operation.
If you are using a connection-oriented xtd::net::sockets::socket, the xtd::net::sockets::socket::receive method will read as much data as is available, up to the size of the buffer. If the remote host shuts down the xtd::net::sockets::socket connection with the xtd::net::sockets::socket::shutdown method, and all available data has been received, the xtd::net::sockets::socket::receive method will complete immediately and return zero bytes.
If you are using a connectionless xtd::net::sockets::socket, xtd::net::sockets::socket::receive will read the first queued datagram from the destination address you specify in the xtd::net::sockets::socket::connect method. If the datagram you receive is larger than the size of the buffer parameter, buffer gets filled with the first part of the message, the excess data is lost and a xtd::net::sockets::socket::socket_exception is thrown.
Note
If you receive a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ receive_from() [1/4]

size_t xtd::net::sockets::socket::receive_from ( std::vector< xtd::byte > &  buffer,
xtd::net::end_point remote_end_point 
)

Receives data from a bound xtd::net::sockets::socket into a receive buffer.

Parameters
bufferAn array of type byte that is the storage location for the received data.
remote_end_pointthe remote host
Returns
The number of bytes received.
Exceptions
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
The xtd::net::sockets::socket::receive_from method reads data into the buffer parameter, returns the number of bytes successfully read, and captures the remote host endpoint from which the data was sent. This method is useful if you intend to receive connectionless datagrams from an unknown host or multiple hosts.
This overload only requires you to provide a receive buffer, and an xtd::net::end_point that represents the remote host. The buffer offset defaults to 0. The size defaults to the size of the buffer parameter and the xtd::net::sockets::socket_flags value defaults to xtd::net::sockets::socket_flags::none.
Note
Before calling xtd::net::sockets::socket::receive_from, you must explicitly bind the xtd::net::sockets::socket to a local endpoint using the xtd::net::sockets::socket::bind method. If you do not, xtd::net::sockets::socket::receive_from will throw a xtd::net::sockets::socket::socket_exception.
Remarks
With connectionless protocols, xtd::net::sockets::socket::receive_from will read the first enqueued datagram received into the local network buffer. If the datagram you receive is larger than the size of buffer, the xtd::net::sockets::socket::receive_from method will fill buffer with as much of the message as is possible, and throw a xtd::net::sockets::socket::socket_exception. If you are using an unreliable protocol, the excess data will be lost. If you are using a reliable protocol, the excess data will be retained by the service provider and you can retrieve it by calling the xtd::net::sockets::socket::receive_from method with a large enough buffer.
If no data is available for reading, the xtd::net::sockets::socket::receive_from method will block until data is available. If you are in non-blocking mode, and there is no data available in the in the protocol stack buffer, the xtd::net::sockets::socket::receive_from method will complete immediately and throw a xtd::net::sockets::socket::socket_exception. You can use the xtd::net::sockets::socket::socket::available property to determine if data is available for reading. When xtd::net::sockets::socket::socket::available is non-zero, retry the receive operation.
Although xtd::net::sockets::socket::receive_from is intended for connectionless protocols, you can use a connection-oriented protocol as well. If you choose to do so, you must first either establish a remote host connection by calling the xtd::net::sockets::socket::socket::connect method or accept an incoming remote host connection by calling the xtd::net::sockets::socket::socket::accept method. If you do not establish or accept a connection before calling the xtd::net::sockets::socket::receive_from method, you will get a xtd::net::sockets::socket::socket_exception. You can also establish a default remote host for a connectionless protocol prior to calling the xtd::net::sockets::socket::receive_from method. In either of these cases, the xtd::net::sockets::socket::receive_from method will ignore the remote_end_point parameter and only receive data from the connected or default remote host.
With connection-oriented sockets, xtd::net::sockets::socket::receive_from will read as much data as is available up to the size of buffer. If the remote host shuts down the xtd::net::sockets::socket connection with the xtd::net::sockets::socket::socket::shutdown method, and all available data has been received, the xtd::net::sockets::socket::receive_from method will complete immediately and return zero bytes.
Note
If you receive a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.
The xtd::net::sockets::sockets::address_family of the xtd::net::end_point used in xtd::net::sockets::socket::receive_from needs to match the xtd::net::sockets::sockets::address_family of the xtd::net::end_point used in xtd::net::sockets::sockets::socket::send_to.

◆ receive_from() [2/4]

size_t xtd::net::sockets::socket::receive_from ( std::vector< xtd::byte > &  buffer,
xtd::net::sockets::socket_flags  socket_flags,
xtd::net::end_point remote_end_point 
)

Receives data from a bound xtd::net::sockets::socket into a receive buffer.

Parameters
bufferAn array of type byte that is the storage location for the received data.
socket_flagsA bitwise combination of the xtd::net::sockets::socket_flags values.
remote_end_pointthe remote host
Returns
The number of bytes received.
Exceptions
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
The xtd::net::sockets::socket::receive_from method reads data into the buffer parameter, returns the number of bytes successfully read, and captures the remote host endpoint from which the data was sent. This method is useful if you intend to receive connectionless datagrams from an unknown host or multiple hosts.
This overload only requires you to provide a receive buffer, the necessary xtd::net::sockets::socket_flags, and an xtd::net::end_point that represents the remote host. The offset defaults to 0 and the size defaults to the size of the buffer parameter.
Note
Before calling xtd::net::sockets::socket::receive_from, you must explicitly bind the xtd::net::sockets::socket to a local endpoint using the xtd::net::sockets::socket::bind method. If you do not, xtd::net::sockets::socket::receive_from will throw a xtd::net::sockets::socket::socket_exception.
Remarks
With connectionless protocols, xtd::net::sockets::socket::receive_from will read the first enqueued datagram received into the local network buffer. If the datagram you receive is larger than the size of buffer, the xtd::net::sockets::socket::receive_from method will fill buffer with as much of the message as is possible, and throw a xtd::net::sockets::socket::socket_exception. If you are using an unreliable protocol, the excess data will be lost. If you are using a reliable protocol, the excess data will be retained by the service provider and you can retrieve it by calling the xtd::net::sockets::socket::receive_from method with a large enough buffer.
If no data is available for reading, the xtd::net::sockets::socket::receive_from method will block until data is available. If you are in non-blocking mode, and there is no data available in the in the protocol stack buffer, the xtd::net::sockets::socket::receive_from method will complete immediately and throw a xtd::net::sockets::socket::socket_exception. You can use the xtd::net::sockets::socket::socket::available property to determine if data is available for reading. When xtd::net::sockets::socket::socket::available is non-zero, retry the receive operation.
Although xtd::net::sockets::socket::receive_from is intended for connectionless protocols, you can use a connection-oriented protocol as well. If you choose to do so, you must first either establish a remote host connection by calling the xtd::net::sockets::socket::socket::connect method or accept an incoming remote host connection by calling the xtd::net::sockets::socket::socket::accept method. If you do not establish or accept a connection before calling the xtd::net::sockets::socket::receive_from method, you will get a xtd::net::sockets::socket::socket_exception. You can also establish a default remote host for a connectionless protocol prior to calling the xtd::net::sockets::socket::receive_from method. In either of these cases, the xtd::net::sockets::socket::receive_from method will ignore the remote_end_point parameter and only receive data from the connected or default remote host.
With connection-oriented sockets, xtd::net::sockets::socket::receive_from will read as much data as is available up to the size of buffer. If the remote host shuts down the xtd::net::sockets::socket connection with the xtd::net::sockets::socket::socket::shutdown method, and all available data has been received, the xtd::net::sockets::socket::receive_from method will complete immediately and return zero bytes.
Note
If you receive a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.
The xtd::net::sockets::sockets::address_family of the xtd::net::end_point used in xtd::net::sockets::socket::receive_from needs to match the xtd::net::sockets::sockets::address_family of the xtd::net::end_point used in xtd::net::sockets::sockets::socket::send_to.

◆ receive_from() [3/4]

size_t xtd::net::sockets::socket::receive_from ( std::vector< xtd::byte > &  buffer,
size_t  size,
xtd::net::sockets::socket_flags  socket_flags,
xtd::net::end_point remote_end_point 
)

Receives data from a bound xtd::net::sockets::socket into a receive buffer.

Parameters
bufferAn array of type byte that is the storage location for the received data.
sizeThe number of bytes to receive.
socket_flagsA bitwise combination of the xtd::net::sockets::socket_flags values.
remote_end_pointthe remote host
Returns
The number of bytes received.
Exceptions
xtd::argument_out_of_range_exceptionsize is less than 0 or exceeds the size of the buffer.
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
The xtd::net::sockets::socket::receive_from method reads data into the buffer parameter, returns the number of bytes successfully read, and captures the remote host endpoint from which the data was sent. This method is useful if you intend to receive connectionless datagrams from an unknown host or multiple hosts.
This overload only requires you to provide a receive buffer, the number of bytes you want to receive, the necessary xtd::net::sockets::socket_flags, and an xtd::net::end_point that represents the remote host. The buffer offset defaults to 0.
Note
Before calling xtd::net::sockets::socket::receive_from, you must explicitly bind the xtd::net::sockets::socket to a local endpoint using the xtd::net::sockets::socket::bind method. If you do not, xtd::net::sockets::socket::receive_from will throw a xtd::net::sockets::socket::socket_exception.
Remarks
With connectionless protocols, xtd::net::sockets::socket::receive_from will read the first enqueued datagram received into the local network buffer. If the datagram you receive is larger than the size of buffer, the xtd::net::sockets::socket::receive_from method will fill buffer with as much of the message as is possible, and throw a xtd::net::sockets::socket::socket_exception. If you are using an unreliable protocol, the excess data will be lost. If you are using a reliable protocol, the excess data will be retained by the service provider and you can retrieve it by calling the xtd::net::sockets::socket::receive_from method with a large enough buffer.
If no data is available for reading, the xtd::net::sockets::socket::receive_from method will block until data is available. If you are in non-blocking mode, and there is no data available in the in the protocol stack buffer, the xtd::net::sockets::socket::receive_from method will complete immediately and throw a xtd::net::sockets::socket::socket_exception. You can use the xtd::net::sockets::socket::socket::available property to determine if data is available for reading. When xtd::net::sockets::socket::socket::available is non-zero, retry the receive operation.
Although xtd::net::sockets::socket::receive_from is intended for connectionless protocols, you can use a connection-oriented protocol as well. If you choose to do so, you must first either establish a remote host connection by calling the xtd::net::sockets::socket::socket::connect method or accept an incoming remote host connection by calling the xtd::net::sockets::socket::socket::accept method. If you do not establish or accept a connection before calling the xtd::net::sockets::socket::receive_from method, you will get a xtd::net::sockets::socket::socket_exception. You can also establish a default remote host for a connectionless protocol prior to calling the xtd::net::sockets::socket::receive_from method. In either of these cases, the xtd::net::sockets::socket::receive_from method will ignore the remote_end_point parameter and only receive data from the connected or default remote host.
With connection-oriented sockets, xtd::net::sockets::socket::receive_from will read as much data as is available up to the size of buffer. If the remote host shuts down the xtd::net::sockets::socket connection with the xtd::net::sockets::socket::socket::shutdown method, and all available data has been received, the xtd::net::sockets::socket::receive_from method will complete immediately and return zero bytes.
Note
If you receive a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.
The xtd::net::sockets::sockets::address_family of the xtd::net::end_point used in xtd::net::sockets::socket::receive_from needs to match the xtd::net::sockets::sockets::address_family of the xtd::net::end_point used in xtd::net::sockets::sockets::socket::send_to.

◆ receive_from() [4/4]

size_t xtd::net::sockets::socket::receive_from ( std::vector< xtd::byte > &  buffer,
size_t  offset,
size_t  size,
xtd::net::sockets::socket_flags  socket_flags,
xtd::net::end_point remote_end_point 
)

Receives data from a bound xtd::net::sockets::socket into a receive buffer.

Parameters
bufferAn array of type byte that is the storage location for the received data.
offsetThe position in the buffer parameter to store the received data.
sizeThe number of bytes to receive.
socket_flagsA bitwise combination of the xtd::net::sockets::socket_flags values.
remote_end_pointthe remote host
Returns
The number of bytes received.
Exceptions
xtd::argument_out_of_range_exceptionsize is less than 0 or exceeds the size of the buffer.
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
The xtd::net::sockets::socket::receive_from method reads data into the buffer parameter, returns the number of bytes successfully read, and captures the remote host endpoint from which the data was sent. This method is useful if you intend to receive connectionless datagrams from an unknown host or multiple hosts.
Note
Before calling xtd::net::sockets::socket::receive_from, you must explicitly bind the xtd::net::sockets::socket to a local endpoint using the xtd::net::sockets::socket::bind method. If you do not, xtd::net::sockets::socket::receive_from will throw a xtd::net::sockets::socket::socket_exception.
Remarks
With connectionless protocols, xtd::net::sockets::socket::receive_from will read the first enqueued datagram received into the local network buffer. If the datagram you receive is larger than the size of buffer, the xtd::net::sockets::socket::receive_from method will fill buffer with as much of the message as is possible, and throw a xtd::net::sockets::socket::socket_exception. If you are using an unreliable protocol, the excess data will be lost. If you are using a reliable protocol, the excess data will be retained by the service provider and you can retrieve it by calling the xtd::net::sockets::socket::receive_from method with a large enough buffer.
If no data is available for reading, the xtd::net::sockets::socket::receive_from method will block until data is available. If you are in non-blocking mode, and there is no data available in the in the protocol stack buffer, the xtd::net::sockets::socket::receive_from method will complete immediately and throw a xtd::net::sockets::socket::socket_exception. You can use the xtd::net::sockets::socket::socket::available property to determine if data is available for reading. When xtd::net::sockets::socket::socket::available is non-zero, retry the receive operation.
Although xtd::net::sockets::socket::receive_from is intended for connectionless protocols, you can use a connection-oriented protocol as well. If you choose to do so, you must first either establish a remote host connection by calling the xtd::net::sockets::socket::socket::connect method or accept an incoming remote host connection by calling the xtd::net::sockets::socket::socket::accept method. If you do not establish or accept a connection before calling the xtd::net::sockets::socket::receive_from method, you will get a xtd::net::sockets::socket::socket_exception. You can also establish a default remote host for a connectionless protocol prior to calling the xtd::net::sockets::socket::receive_from method. In either of these cases, the xtd::net::sockets::socket::receive_from method will ignore the remote_end_point parameter and only receive data from the connected or default remote host.
With connection-oriented sockets, xtd::net::sockets::socket::receive_from will read as much data as is available up to the size of buffer. If the remote host shuts down the xtd::net::sockets::socket connection with the xtd::net::sockets::socket::socket::shutdown method, and all available data has been received, the xtd::net::sockets::socket::receive_from method will complete immediately and return zero bytes.
Note
If you receive a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.
The xtd::net::sockets::sockets::address_family of the xtd::net::end_point used in xtd::net::sockets::socket::receive_from needs to match the xtd::net::sockets::sockets::address_family of the xtd::net::end_point used in xtd::net::sockets::sockets::socket::send_to.

◆ send() [1/5]

size_t xtd::net::sockets::socket::send ( const std::vector< xtd::byte > &  buffer)

Sends data to a connected xtd::net::sockets::socket.

Parameters
bufferAn array of type byte that contains the data to be sent.
Returns
The number of bytes sent to the xtd::net::sockets::socket.
Exceptions
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
xtd::net::sockets::socket::send synchronously sends data to the remote host specified in the xtd::net::sockets::socket::connect or xtd::net::sockets::socket::accept method and returns the number of bytes successfully sent. xtd::net::sockets::socket::send can be used for both connection-oriented and connectionless protocols.
This overload requires a buffer that contains the data you want to send. The xtd::net::sockets::socket_flags value defaults to xtd::net::sockets::socket_flags::none, the buffer offset defaults to 0, and the number of bytes to send defaults to the size of the buffer.
If you are using a connectionless protocol, you must call xtd::net::sockets::socket::connect before calling this method, or xtd::net::sockets::socket::send will throw a xtd::net::sockets::socket_exception. If you are using a connection-oriented protocol, you must either use xtd::net::sockets::socket::connect to establish a remote host connection, or use xtd::net::sockets::socket::accept to accept an incoming connection.
If you are using a connectionless protocol and plan to send data to several different hosts, you should use the xtd::net::sockets::socket::send_to method. If you do not use the xtd::net::sockets::socket::send_to method, you will have to call xtd::net::sockets::socket::connect before each call to xtd::net::sockets::socket::send. You can use xtd::net::sockets::socket::send_to even after you have established a default remote host with xtd::net::sockets::socket::connect. You can also change the default remote host prior to calling xtd::net::sockets::socket::send by making another call to xtd::net::sockets::socket::connect.
If you are using a connection-oriented protocol, xtd::net::sockets::socket::send will block until all of the bytes in the buffer are sent, unless a time-out was set by using xtd::net::sockets::socket::send_timeout. If the time-out value was exceeded, the xtd::net::sockets::socket::send call will throw a xtd::net::sockets::socket_exception. In nonblocking mode, xtd::net::sockets::socket::send may complete successfully even if it sends less than the number of bytes in the buffer. It is your application's responsibility to keep track of the number of bytes sent and to retry the operation until the application sends the bytes in the buffer. There is also no guarantee that the data you send will appear on the network immediately. To increase network efficiency, the underlying system may delay transmission until a significant amount of outgoing data is collected. A successful completion of the Send method means that the underlying system has had room to buffer your data for a network send.
Note
The successful completion of a send does not indicate that the data was successfully delivered. If no buffer space is available within the transport system to hold the data to be transmitted, send will block unless the socket has been placed in nonblocking mode.
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.
Examples
socket_tcp_ip_v4_without_thread.cpp.

◆ send() [2/5]

size_t xtd::net::sockets::socket::send ( const std::vector< xtd::byte > &  buffer,
xtd::net::sockets::socket_flags  socket_flags 
)

Sends data to a connected xtd::net::sockets::socket using the specified xtd::net::sockets::socket_flags.

Parameters
bufferAn array of type byte that contains the data to be sent.
socket_flagsA bitwise combination of the xtd::net::sockets::socket_flags values.
Returns
The number of bytes sent to the xtd::net::sockets::socket.
Exceptions
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
xtd::net::sockets::socket::send synchronously sends data to the remote host specified in the xtd::net::sockets::socket::connect or xtd::net::sockets::socket::accept method and returns the number of bytes successfully sent. xtd::net::sockets::socket::send can be used for both connection-oriented and connectionless protocols.
This overload requires a buffer that contains the data you want to send and a bitwise combination of xtd::net::sockets::socket_flags. The buffer offset defaults to 0, and the number of bytes to send defaults to the size of the buffer. If you specify the xtd::net::sockets::socket_flags::dont_route flag as the socket_flags parameter value, the data you are sending will not be routed.
If you are using a connectionless protocol, you must call xtd::net::sockets::socket::connect before calling this method, or xtd::net::sockets::socket::send will throw a xtd::net::sockets::socket_exception. If you are using a connection-oriented protocol, you must either use xtd::net::sockets::socket::connect to establish a remote host connection, or use xtd::net::sockets::socket::accept to accept an incoming connection.
If you are using a connectionless protocol and plan to send data to several different hosts, you should use the xtd::net::sockets::socket::send_to method. If you do not use the xtd::net::sockets::socket::send_to method, you will have to call xtd::net::sockets::socket::connect before each call to xtd::net::sockets::socket::send. You can use xtd::net::sockets::socket::send_to even after you have established a default remote host with xtd::net::sockets::socket::connect. You can also change the default remote host prior to calling xtd::net::sockets::socket::send by making another call to xtd::net::sockets::socket::connect.
If you are using a connection-oriented protocol, xtd::net::sockets::socket::send will block until all of the bytes in the buffer are sent, unless a time-out was set by using xtd::net::sockets::socket::send_timeout. If the time-out value was exceeded, the xtd::net::sockets::socket::send call will throw a xtd::net::sockets::socket_exception. In nonblocking mode, xtd::net::sockets::socket::send may complete successfully even if it sends less than the number of bytes in the buffer. It is your application's responsibility to keep track of the number of bytes sent and to retry the operation until the application sends the bytes in the buffer. There is also no guarantee that the data you send will appear on the network immediately. To increase network efficiency, the underlying system may delay transmission until a significant amount of outgoing data is collected. A successful completion of the Send method means that the underlying system has had room to buffer your data for a network send.
Note
The successful completion of a send does not indicate that the data was successfully delivered. If no buffer space is available within the transport system to hold the data to be transmitted, send will block unless the socket has been placed in nonblocking mode.
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ send() [3/5]

size_t xtd::net::sockets::socket::send ( const std::vector< xtd::byte > &  buffer,
size_t  size,
xtd::net::sockets::socket_flags  socket_flags 
)

Sends the specified number of bytes of data to a connected xtd::net::sockets::socket, using the specified xtd::net::sockets::socket_flags.

Parameters
bufferAn array of type byte that contains the data to be sent.
sizeThe number of bytes to send.
socket_flagsA bitwise combination of the xtd::net::sockets::socket_flags values.
Returns
The number of bytes sent to the xtd::net::sockets::socket.
Exceptions
xtd::argument_out_of_range_exceptionsize is less than 0 or exceeds the size of the buffer.
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
xtd::net::sockets::socket::send synchronously sends data to the remote host specified in the xtd::net::sockets::socket::connect or xtd::net::sockets::socket::accept method and returns the number of bytes successfully sent. xtd::net::sockets::socket::send can be used for both connection-oriented and connectionless protocols.
This overload requires a buffer that contains the data you want to send, the number of bytes you want to send, and a bitwise combination of any xtd::net::sockets::socket_flags. If you specify the xtd::net::sockets::socket_flags::dont_route flag as the socket_flags parameter, the data you're sending won't be routed.
If you are using a connectionless protocol, you must call xtd::net::sockets::socket::connect before calling this method, or xtd::net::sockets::socket::send will throw a xtd::net::sockets::socket_exception. If you are using a connection-oriented protocol, you must either use xtd::net::sockets::socket::connect to establish a remote host connection, or use xtd::net::sockets::socket::accept to accept an incoming connection.
If you are using a connectionless protocol and plan to send data to several different hosts, you should use the xtd::net::sockets::socket::send_to method. If you do not use the xtd::net::sockets::socket::send_to method, you will have to call xtd::net::sockets::socket::connect before each call to xtd::net::sockets::socket::send. You can use xtd::net::sockets::socket::send_to even after you have established a default remote host with xtd::net::sockets::socket::connect. You can also change the default remote host prior to calling xtd::net::sockets::socket::send by making another call to xtd::net::sockets::socket::connect.
If you are using a connection-oriented protocol, xtd::net::sockets::socket::send will block until all of the bytes in the buffer are sent, unless a time-out was set by using xtd::net::sockets::socket::send_timeout. If the time-out value was exceeded, the xtd::net::sockets::socket::send call will throw a xtd::net::sockets::socket_exception. In nonblocking mode, xtd::net::sockets::socket::send may complete successfully even if it sends less than the number of bytes in the buffer. It is your application's responsibility to keep track of the number of bytes sent and to retry the operation until the application sends the bytes in the buffer. There is also no guarantee that the data you send will appear on the network immediately. To increase network efficiency, the underlying system may delay transmission until a significant amount of outgoing data is collected. A successful completion of the Send method means that the underlying system has had room to buffer your data for a network send.
Note
The successful completion of a send does not indicate that the data was successfully delivered. If no buffer space is available within the transport system to hold the data to be transmitted, send will block unless the socket has been placed in nonblocking mode.
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ send() [4/5]

size_t xtd::net::sockets::socket::send ( const std::vector< xtd::byte > &  buffer,
size_t  offset,
size_t  size,
xtd::net::sockets::socket_flags  socket_flags 
)

Sends the specified number of bytes of data to a connected xtd::net::sockets::socket, starting at the specified offset, and using the specified xtd::net::sockets::socket_flags.

Parameters
bufferAn array of type byte that contains the data to be sent.
offsetThe position in the data buffer at which to begin sending data.
sizeThe number of bytes to send.
socket_flagsA bitwise combination of the xtd::net::sockets::socket_flags values.
Returns
The number of bytes sent to the xtd::net::sockets::socket.
Exceptions
xtd::argument_out_of_range_exceptionsize is less than 0 or exceeds the size of the buffer.
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
xtd::net::sockets::socket::send synchronously sends data to the remote host specified in the xtd::net::sockets::socket::connect or xtd::net::sockets::socket::accept method and returns the number of bytes successfully sent. xtd::net::sockets::socket::send can be used for both connection-oriented and connectionless protocols.
In this overload, if you specify the xtd::net::sockets::socket_flags::dont_route flag as the socket_flags parameter, the data you're sending won't be routed.
If you are using a connectionless protocol, you must call xtd::net::sockets::socket::connect before calling this method, or xtd::net::sockets::socket::send will throw a xtd::net::sockets::socket_exception. If you are using a connection-oriented protocol, you must either use xtd::net::sockets::socket::connect to establish a remote host connection, or use xtd::net::sockets::socket::accept to accept an incoming connection.
If you are using a connectionless protocol and plan to send data to several different hosts, you should use the xtd::net::sockets::socket::send_to method. If you do not use the xtd::net::sockets::socket::send_to method, you will have to call xtd::net::sockets::socket::connect before each call to xtd::net::sockets::socket::send. You can use xtd::net::sockets::socket::send_to even after you have established a default remote host with xtd::net::sockets::socket::connect. You can also change the default remote host prior to calling xtd::net::sockets::socket::send by making another call to xtd::net::sockets::socket::connect.
If you are using a connection-oriented protocol, xtd::net::sockets::socket::send will block until all of the bytes in the buffer are sent, unless a time-out was set by using xtd::net::sockets::socket::send_timeout. If the time-out value was exceeded, the xtd::net::sockets::socket::send call will throw a xtd::net::sockets::socket_exception. In nonblocking mode, xtd::net::sockets::socket::send may complete successfully even if it sends less than the number of bytes in the buffer. It is your application's responsibility to keep track of the number of bytes sent and to retry the operation until the application sends the bytes in the buffer. There is also no guarantee that the data you send will appear on the network immediately. To increase network efficiency, the underlying system may delay transmission until a significant amount of outgoing data is collected. A successful completion of the Send method means that the underlying system has had room to buffer your data for a network send.
Note
The successful completion of a send does not indicate that the data was successfully delivered. If no buffer space is available within the transport system to hold the data to be transmitted, send will block unless the socket has been placed in nonblocking mode.
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ send() [5/5]

size_t xtd::net::sockets::socket::send ( const std::vector< xtd::byte > &  buffer,
size_t  offset,
size_t  size,
xtd::net::sockets::socket_flags  socket_flags,
xtd::net::sockets::socket_error error_code 
)

Sends the specified number of bytes of data to a connected xtd::net::sockets::socket, starting at the specified offset, and using the specified xtd::net::sockets::socket_flags.

Parameters
bufferAn array of type byte that contains the data to be sent.
offsetThe position in the data buffer at which to begin sending data.
sizeThe number of bytes to send.
socket_flagsA bitwise combination of the xtd::net::sockets::socket_flags values.
error_codeA xtd::net::sockets::socket_error object that stores the socket error.
Returns
The number of bytes sent to the xtd::net::sockets::socket.
Exceptions
xtd::argument_out_of_range_exceptionsize is less than 0 or exceeds the size of the buffer.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
xtd::net::sockets::socket::send synchronously sends data to the remote host specified in the xtd::net::sockets::socket::connect or xtd::net::sockets::socket::accept method and returns the number of bytes successfully sent. xtd::net::sockets::socket::send can be used for both connection-oriented and connectionless protocols.
In this overload, if you specify the xtd::net::sockets::socket_flags::dont_route flag as the socket_flags parameter, the data you're sending won't be routed.
If you are using a connectionless protocol, you must call xtd::net::sockets::socket::connect before calling this method, or xtd::net::sockets::socket::send will throw a xtd::net::sockets::socket_exception. If you are using a connection-oriented protocol, you must either use xtd::net::sockets::socket::connect to establish a remote host connection, or use xtd::net::sockets::socket::accept to accept an incoming connection.
If you are using a connectionless protocol and plan to send data to several different hosts, you should use the xtd::net::sockets::socket::send_to method. If you do not use the xtd::net::sockets::socket::send_to method, you will have to call xtd::net::sockets::socket::connect before each call to xtd::net::sockets::socket::send. You can use xtd::net::sockets::socket::send_to even after you have established a default remote host with xtd::net::sockets::socket::connect. You can also change the default remote host prior to calling xtd::net::sockets::socket::send by making another call to xtd::net::sockets::socket::connect.
If you are using a connection-oriented protocol, xtd::net::sockets::socket::send will block until all of the bytes in the buffer are sent, unless a time-out was set by using xtd::net::sockets::socket::send_timeout. If the time-out value was exceeded, the xtd::net::sockets::socket::send call will throw a xtd::net::sockets::socket_exception. In nonblocking mode, xtd::net::sockets::socket::send may complete successfully even if it sends less than the number of bytes in the buffer. It is your application's responsibility to keep track of the number of bytes sent and to retry the operation until the application sends the bytes in the buffer. There is also no guarantee that the data you send will appear on the network immediately. To increase network efficiency, the underlying system may delay transmission until a significant amount of outgoing data is collected. A successful completion of the Send method means that the underlying system has had room to buffer your data for a network send.
Note
The successful completion of a send does not indicate that the data was successfully delivered. If no buffer space is available within the transport system to hold the data to be transmitted, send will block unless the socket has been placed in nonblocking mode.

◆ send_to() [1/4]

size_t xtd::net::sockets::socket::send_to ( const std::vector< xtd::byte > &  buffer,
const xtd::net::end_point remote_end_point 
)

Sends data to the specified endpoint.

Parameters
bufferAn array of type byte that contains the data to be sent.
remote_end_pointThe xtd::net::end_point that represents the destination for the data.
Returns
The number of bytes sent.
Exceptions
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
In this overload, the buffer offset defaults to 0, the number of bytes to send defaults to the size of the buffer parameter, and the xtd::net::sockets::socket_flags value defaults to xtd::net::sockets::socket_flags::none.
If you are using a connectionless protocol, you do not need to establish a default remote host with the xtd::net::sockets::socket::connect method prior to calling xtd::net::sockets::socket::send_to. You only need to do this if you intend to call the xtd::net::sockets::socket::send method. If you do call the xtd::net::sockets::socket::connect method prior to calling xtd::net::sockets::socket::send_tto, the remote_end_point parameter will override the specified default remote host for that send operation only. You are also not required to call the xtd::net::sockets::socket::bind method, because the underlying service provider will assign the most appropriate local network address and port number. If you need to identify the assigned local network address and port number, you can use the xtd::net::sockets::socket::local_end_point property after the xtd::net::sockets::socket::send_to method successfully completes.
Although intended for connectionless protocols, xtd::net::sockets::socket::send_to also works with connection-oriented protocols. If you are using a connection-oriented protocol, you must first establish a remote host connection by calling the xtd::net::sockets::socket::connect method or accept an incoming connection request using the xtd::net::sockets::socket::accept method. If you do not establish or accept a remote host connection, xtd::net::sockets::socket::send_to will throw a xtd::net::sockets::socket_exception. You can also establish a default remote host for a connectionless protocol prior to calling the xtd::net::sockets::socket::send_to method. In either of these cases, xtd::net::sockets::socket::send_to will ignore the remote_end_point parameter and only send data to the connected or default remote host.
Blocking sockets will block until the all of the bytes in the buffer are sent. Since a nonblocking xtd::net::sockets::socket completes immediately, it might not send all of the bytes in the buffer. It is your application's responsibility to keep track of the number of bytes sent and to retry the operation until the application sends all of the bytes in the buffer. There is also no guarantee that the data you send will appear on the network immediately. To increase network efficiency, the underlying system may delay transmission until a significant amount of outgoing data is collected. A successful completion of the xtd::net::sockets::socket::send_to method means that the underlying system has had room to buffer your data for a network send.
If you are using a connectionless protocol in blocking mode, xtd::net::sockets::socket::send_to will block until the datagram is sent. If you want to send data to a broadcast address, you must first call the xtd::net::sockets::socket::set_socket_option method and set the socket option to xtd::net::sockets::socket_option_name::broadcast. You must also be sure that the number of bytes sent does not exceed the maximum packet size of the underlying service provider. If it does, the datagram will not be sent and xtd::net::sockets::socket::send_to will throw a xtd::net::sockets::socket_exception.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ send_to() [2/4]

size_t xtd::net::sockets::socket::send_to ( const std::vector< xtd::byte > &  buffer,
xtd::net::sockets::socket_flags  socket_flags,
const xtd::net::end_point remote_end_point 
)

Sends data to a specific endpoint using the specified xtd::net::sockets::socket_flags.

Parameters
socket_flagsA bitwise combination of the xtd::net::sockets::socket_flags values.
bufferAn array of type byte that contains the data to be sent.
remote_end_pointThe xtd::net::end_point that represents the destination for the data.
Returns
The number of bytes sent.
Exceptions
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
IIn this overload, the buffer offset defaults to 0, and the number of bytes to send defaults to the size of the buffer. If you specify the xtd::net::sockets::socket_flags::dont_route flag as the socket_flags parameter, the data you are sending will not be routed.
If you are using a connectionless protocol, you do not need to establish a default remote host with the xtd::net::sockets::socket::connect method prior to calling xtd::net::sockets::socket::send_to. You only need to do this if you intend to call the xtd::net::sockets::socket::send method. If you do call the xtd::net::sockets::socket::connect method prior to calling xtd::net::sockets::socket::send_tto, the remote_end_point parameter will override the specified default remote host for that send operation only. You are also not required to call the xtd::net::sockets::socket::bind method, because the underlying service provider will assign the most appropriate local network address and port number. If you need to identify the assigned local network address and port number, you can use the xtd::net::sockets::socket::local_end_point property after the xtd::net::sockets::socket::send_to method successfully completes.
Although intended for connectionless protocols, xtd::net::sockets::socket::send_to also works with connection-oriented protocols. If you are using a connection-oriented protocol, you must first establish a remote host connection by calling the xtd::net::sockets::socket::connect method or accept an incoming connection request using the xtd::net::sockets::socket::accept method. If you do not establish or accept a remote host connection, xtd::net::sockets::socket::send_to will throw a xtd::net::sockets::socket_exception. You can also establish a default remote host for a connectionless protocol prior to calling the xtd::net::sockets::socket::send_to method. In either of these cases, xtd::net::sockets::socket::send_to will ignore the remote_end_point parameter and only send data to the connected or default remote host.
Blocking sockets will block until the all of the bytes in the buffer are sent. Since a nonblocking xtd::net::sockets::socket completes immediately, it might not send all of the bytes in the buffer. It is your application's responsibility to keep track of the number of bytes sent and to retry the operation until the application sends all of the bytes in the buffer. There is also no guarantee that the data you send will appear on the network immediately. To increase network efficiency, the underlying system may delay transmission until a significant amount of outgoing data is collected. A successful completion of the xtd::net::sockets::socket::send_to method means that the underlying system has had room to buffer your data for a network send.
If you are using a connectionless protocol in blocking mode, xtd::net::sockets::socket::send_to will block until the datagram is sent. If you want to send data to a broadcast address, you must first call the xtd::net::sockets::socket::set_socket_option method and set the socket option to xtd::net::sockets::socket_option_name::broadcast. You must also be sure that the number of bytes sent does not exceed the maximum packet size of the underlying service provider. If it does, the datagram will not be sent and xtd::net::sockets::socket::send_to will throw a xtd::net::sockets::socket_exception.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ send_to() [3/4]

size_t xtd::net::sockets::socket::send_to ( const std::vector< xtd::byte > &  buffer,
size_t  size,
xtd::net::sockets::socket_flags  socket_flags,
const xtd::net::end_point remote_end_point 
)

Sends the specified number of bytes of data to the specified endpoint using the specified xtd::net::sockets::socket_flags.

Parameters
bufferAn array of type byte that contains the data to be sent.
sizeThe number of bytes to send.
socket_flagsA bitwise combination of the xtd::net::sockets::socket_flags values.
remote_end_pointThe xtd::net::end_point that represents the destination for the data.
Returns
The number of bytes sent.
Exceptions
xtd::argument_out_of_range_exceptionsize is less than 0 or exceeds the size of the buffer.
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
In this overload, the buffer offset defaults to 0. If you specify the xtd::net::sockets::socket_flags::dont_route flag as the socket_flags parameter, the data you are sending will not be routed.
If you are using a connectionless protocol, you do not need to establish a default remote host with the xtd::net::sockets::socket::connect method prior to calling xtd::net::sockets::socket::send_to. You only need to do this if you intend to call the xtd::net::sockets::socket::send method. If you do call the xtd::net::sockets::socket::connect method prior to calling xtd::net::sockets::socket::send_tto, the remote_end_point parameter will override the specified default remote host for that send operation only. You are also not required to call the xtd::net::sockets::socket::bind method, because the underlying service provider will assign the most appropriate local network address and port number. If you need to identify the assigned local network address and port number, you can use the xtd::net::sockets::socket::local_end_point property after the xtd::net::sockets::socket::send_to method successfully completes.
Although intended for connectionless protocols, xtd::net::sockets::socket::send_to also works with connection-oriented protocols. If you are using a connection-oriented protocol, you must first establish a remote host connection by calling the xtd::net::sockets::socket::connect method or accept an incoming connection request using the xtd::net::sockets::socket::accept method. If you do not establish or accept a remote host connection, xtd::net::sockets::socket::send_to will throw a xtd::net::sockets::socket_exception. You can also establish a default remote host for a connectionless protocol prior to calling the xtd::net::sockets::socket::send_to method. In either of these cases, xtd::net::sockets::socket::send_to will ignore the remote_end_point parameter and only send data to the connected or default remote host.
Blocking sockets will block until the all of the bytes in the buffer are sent. Since a nonblocking xtd::net::sockets::socket completes immediately, it might not send all of the bytes in the buffer. It is your application's responsibility to keep track of the number of bytes sent and to retry the operation until the application sends all of the bytes in the buffer. There is also no guarantee that the data you send will appear on the network immediately. To increase network efficiency, the underlying system may delay transmission until a significant amount of outgoing data is collected. A successful completion of the xtd::net::sockets::socket::send_to method means that the underlying system has had room to buffer your data for a network send.
If you are using a connectionless protocol in blocking mode, xtd::net::sockets::socket::send_to will block until the datagram is sent. If you want to send data to a broadcast address, you must first call the xtd::net::sockets::socket::set_socket_option method and set the socket option to xtd::net::sockets::socket_option_name::broadcast. You must also be sure that the number of bytes sent does not exceed the maximum packet size of the underlying service provider. If it does, the datagram will not be sent and xtd::net::sockets::socket::send_to will throw a xtd::net::sockets::socket_exception.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ send_to() [4/4]

size_t xtd::net::sockets::socket::send_to ( const std::vector< xtd::byte > &  buffer,
size_t  offset,
size_t  size,
xtd::net::sockets::socket_flags  socket_flags,
const xtd::net::end_point remote_end_point 
)

Sends the specified number of bytes of data to the specified endpoint, starting at the specified location in the buffer, and using the specified xtd::net::sockets::socket_flags.

Parameters
bufferAn array of type byte that contains the data to be sent.
offsetThe position in the data buffer at which to begin sending data.
sizeThe number of bytes to send.
socket_flagsA bitwise combination of the xtd::net::sockets::socket_flags values.
remote_end_pointThe xtd::net::end_point that represents the destination for the data.
Returns
The number of bytes sent.
Exceptions
xtd::argument_out_of_range_exceptionsize is less than 0 or exceeds the size of the buffer.
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
In this overload, if you specify the xtd::net::sockets::socket_flags::dont_route flag as the socket_flags parameter, the data you are sending will not be routed.
If you are using a connectionless protocol, you do not need to establish a default remote host with the xtd::net::sockets::socket::connect method prior to calling xtd::net::sockets::socket::send_to. You only need to do this if you intend to call the xtd::net::sockets::socket::send method. If you do call the xtd::net::sockets::socket::connect method prior to calling xtd::net::sockets::socket::send_tto, the remote_end_point parameter will override the specified default remote host for that send operation only. You are also not required to call the xtd::net::sockets::socket::bind method, because the underlying service provider will assign the most appropriate local network address and port number. If you need to identify the assigned local network address and port number, you can use the xtd::net::sockets::socket::local_end_point property after the xtd::net::sockets::socket::send_to method successfully completes.
Although intended for connectionless protocols, xtd::net::sockets::socket::send_to also works with connection-oriented protocols. If you are using a connection-oriented protocol, you must first establish a remote host connection by calling the xtd::net::sockets::socket::connect method or accept an incoming connection request using the xtd::net::sockets::socket::accept method. If you do not establish or accept a remote host connection, xtd::net::sockets::socket::send_to will throw a xtd::net::sockets::socket_exception. You can also establish a default remote host for a connectionless protocol prior to calling the xtd::net::sockets::socket::send_to method. In either of these cases, xtd::net::sockets::socket::send_to will ignore the remote_end_point parameter and only send data to the connected or default remote host.
Blocking sockets will block until the all of the bytes in the buffer are sent. Since a nonblocking xtd::net::sockets::socket completes immediately, it might not send all of the bytes in the buffer. It is your application's responsibility to keep track of the number of bytes sent and to retry the operation until the application sends all of the bytes in the buffer. There is also no guarantee that the data you send will appear on the network immediately. To increase network efficiency, the underlying system may delay transmission until a significant amount of outgoing data is collected. A successful completion of the xtd::net::sockets::socket::send_to method means that the underlying system has had room to buffer your data for a network send.
If you are using a connectionless protocol in blocking mode, xtd::net::sockets::socket::send_to will block until the datagram is sent. If you want to send data to a broadcast address, you must first call the xtd::net::sockets::socket::set_socket_option method and set the socket option to xtd::net::sockets::socket_option_name::broadcast. You must also be sure that the number of bytes sent does not exceed the maximum packet size of the underlying service provider. If it does, the datagram will not be sent and xtd::net::sockets::socket::send_to will throw a xtd::net::sockets::socket_exception.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ set_ip_protection_level()

void xtd::net::sockets::socket::set_ip_protection_level ( xtd::net::sockets::ip_protection_level  level)

Sets the IP protection level on a socket.

Parameters
levelThe IP protection level to set on this socket.The IP protection level to set on this socket.
Exceptions
xtd::argument_exceptionThe level argument is set to xtd::net::sockets::ip_protection_level::unspecified.
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::not_supported_exceptionThe socket is not in the xtd::net::sockets::address_family::inter_network_v6 or xtd::net::sockets::address_family::inter_network address families.
Remarks
The xtd::net::sockets::socket::set_ip_protection_level method enables restricting an a IPv6 or IP socket to listen on a specified scope, such as addresses with the same link local or site local prefix. This socket option enables applications to place access restrictions on IPv6 or IP sockets. Such restrictions enable an application running on a private LAN to simply and robustly harden itself against external attacks. This socket option can also be used to remove access restrictions if the level parameter is set to xtd::net::sockets::ip_protection_level xtd::net::sockets::ip_protection_level::unrestricted. This socket option widens or narrows the scope of a listening socket, enabling unrestricted access from public and private users when appropriate, or restricting access only to the same site, as required.
This socket option has defined protection levels specified in the xtd::net::sockets::ip_protection_level enumeration.
The xtd::net::sockets::socket::set_ip_protection_level method is used to enable or disable Network Address Traversal (NAT) for a xtd::net::sockets::socket instance. NAT traversal may be provided using Teredo, 6to4, or an ISATAP tunnel.
When the level parameter is set to xtd::net::sockets::ip_protection_level::edge_restricted, or xtd::net::sockets::ip_protection_level::restricted, this explicitly disables NAT traversal for a xtd::net::sockets::socket instance.
When the level parameter is set to xtd::net::sockets::ip_protection_level::edge_restricted, this may allow NAT traversal for a xtd::net::sockets::socket depending on firewall rules in place on the system.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ set_socket_option() [1/5]

void xtd::net::sockets::socket::set_socket_option ( xtd::net::sockets::socket_option_level  socket_option_level,
xtd::net::sockets::socket_option_name  socket_option_name,
bool  option_value 
)

Sets the specified xtd::net::sockets::socket option to the specified integer value.

Parameters
socket_option_levelOne of the xtd::net::sockets::socket_option_level values.
socket_option_nameOne of the xtd::net::sockets::socket_option_name values.
option_valueA value of the option.
Exceptions
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
xtd::net::sockets::socket options determine the behavior of the current xtd::net::sockets::socket. For an option with a Boolean data type, specify a nonzero value to enable the option, and a zero value to disable the option. For an option with an integer data type, specify the appropriate value. xtd::net::sockets::socket options are grouped by level of protocol support.
xtd::net::sockets::socket options are grouped by level of protocol support.
Listed below are the various xtd::net::sockets::socket options that can be set using this overload. These options are grouped by the appropriate SocketOptionLevel value. If you intend to set any of these options, be sure to use the appropriate SocketOptionLevel value for the optionLevel parameter. The option you choose to set must be specified in the optionName parameter. If you want to get the current value of any of the options listed, use the GetSocketOption method.

For more information on these options, refer to the xtd::net::sockets::socket_option_name enumeration.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ set_socket_option() [2/5]

void xtd::net::sockets::socket::set_socket_option ( xtd::net::sockets::socket_option_level  socket_option_level,
xtd::net::sockets::socket_option_name  socket_option_name,
int32  option_value 
)

Sets the specified xtd::net::sockets::socket option to the specified integer value.

Parameters
socket_option_levelOne of the xtd::net::sockets::socket_option_level values.
socket_option_nameOne of the xtd::net::sockets::socket_option_name values.
option_valueA value of the option.
Exceptions
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
xtd::net::sockets::socket options determine the behavior of the current xtd::net::sockets::socket. For an option with a bool data type, specify a nonzero value to enable the option, and a zero value to disable the option. For an option with an int data type, specify the appropriate value. xtd::net::sockets::socket options are grouped by level of protocol support.
Listed below are the various xtd::net::sockets::socket options that can be set using this overload. These options are grouped by the appropriate xtd::net::sockets::socket_option_level. If you intend to set any of these options, be sure to use the appropriate xtd::net::sockets::socket_option_level for the optionLevel parameter. The option you choose to set must be specified in the option_ame parameter. If you want to get the current value of any of the options listed, use the xtd::net::sockets::socket::get_socket_option method.

For more information on these options, refer to the xtd::net::sockets::socket_option_name enumeration.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ set_socket_option() [3/5]

void xtd::net::sockets::socket::set_socket_option ( xtd::net::sockets::linger_option  option_value)

Sets the linger xtd::net::sockets::socket option to the specified integer value.

Parameters
option_valueA value of the option.
Exceptions
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ set_socket_option() [4/5]

void xtd::net::sockets::socket::set_socket_option ( xtd::net::sockets::socket_option_name  socket_option_name,
const xtd::net::sockets::multicast_option option_value 
)

Sets the linger xtd::net::sockets::socket option to the specified integer value.

Parameters
socket_option_nameOne of the xtd::net::sockets::socket_option_name values. Only xtd::net::sockets::socket_option_name::add_membership and xtd::net::sockets::socket_option_name::drop_membership values are accepted.
option_valueA value of the option.
Exceptions
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ set_socket_option() [5/5]

void xtd::net::sockets::socket::set_socket_option ( xtd::net::sockets::socket_option_name  socket_option_name,
const xtd::net::sockets::ip_v6_multicast_option option_value 
)

Sets the linger xtd::net::sockets::socket option to the specified integer value.

Parameters
socket_option_nameOne of the xtd::net::sockets::socket_option_name values. Only xtd::net::sockets::socket_option_name::add_membership and xtd::net::sockets::socket_option_name::drop_membership values are accepted.
option_valueA value of the option.
Exceptions
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ set_raw_socket_option()

void xtd::net::sockets::socket::set_raw_socket_option ( int32  socket_option_level,
int32  socket_option_name,
intptr  option_value,
size_t  option_value_size 
)

Sets a socket option value using platform-specific level and name identifiers.

Parameters
socket_option_levelThe platform-defined option name.
socket_option_nameThe platform-defined option name.
option_valueA pointer of the option value.
size_option_valueThe size of the option value.
Exceptions
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
In general, the xtd::net::sockets::socket::set_socket_option method should be used whenever setting a xtd::net::sockets::socket option.
The SetRawSocketOption(Int32, Int32, ReadOnlySpan<byte>) method should be used only when SocketOptionLevel and SocketOptionName do not expose the required option.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ shutdown()

void xtd::net::sockets::socket::shutdown ( xtd::net::sockets::socket_shutdown  how)

Disables sends and receives on a xtd::net::sockets::socket.

Parameters
howOne of the xtd::net::sockets::socket_shutdown values that specifies the operation that will no longer be allowed.
Exceptions
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
When using a connection-oriented xtd::net::sockets::socket, always call the xtd::net::sockets::socket::shutdown method before closing the xtd::net::sockets::socket::socket. This ensures that all data is sent and received on the connected socket before it is closed.
Call the xtd::net::sockets::socket::close method to free all resources associated with the xtd::net::sockets::socket. Do not attempt to reuse the xtd::net::sockets::socket after closing.
The following table shows the xtd::net::sockets::socket_shutdown enumeration values that are valid for the how parameter.
Value Description
xtd::net::sockets::socket_shutdown::send Disable sending on this xtd::net::sockets::socket.
xtd::net::sockets::socket_shutdown::receive Disable receiving on this xtd::net::sockets::socket.
xtd::net::sockets::socket_shutdown::both Disable both sending and receiving on this xtd::net::sockets::socket.
Setting how to xtd::net::sockets::socket_shutdown::send specifies that subsequent calls to xtd::net::sockets::socket::send are not allowed. If you are using a connectionless xtd::net::sockets::socket, specifying xtd::net::sockets::socket_shutdown::send will have no effect.
Setting how to xtd::net::sockets::socket_shutdown::receive specifies that subsequent calls to xtd::net::sockets::socket::receive are not allowed. This has no effect on lower protocol layers. If you are using a connection-oriented protocol, the connection is terminated if either of the following conditions exist after a call to xtd::net::sockets::socket::shutdown :
  • Data is in the incoming network buffer waiting to be received.
  • More data has arrived.
If you are using a connectionless protocol, datagrams are accepted and queued. However, if no buffer space is available for additional incoming datagrams, they will be discarded and no error will be returned to the sender. Using xtd::net::sockets::socket::shutdown on a connectionless xtd::net::sockets::socket is not recommended.
Setting how to xtd::net::sockets::socket_shutdown::both disables both sends and receives as described above.
Note
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ select()

static size_t xtd::net::sockets::socket::select ( std::vector< socket > &  check_read,
std::vector< socket > &  check_write,
std::vector< socket > &  check_error,
int32  microseconds 
)
static

Determines the status of one or more sockets.

Parameters
check_readAn array of xtd::net::sockets::socket instances to check for readability.
check_writeAn array of xtd::net::sockets::socket instances to check for writability.
check_errorAn array of xtd::net::sockets::socket instances to check for errors.
microsecondsThe time-out value, in microseconds. A -1 value indicates an infinite time-out.
Returns
0 if the timeout expired; otherwise, the total number of sockets returned in the lists.
Exceptions
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
Remarks
xtd::net::sockets::socket::select is a static method that determines the status of one or more xtd::net::sockets::socket instances. You must place one or more sockets into an array before you can use the xtd::net::sockets::socket::select method. Check for readability by calling xtd::net::sockets::socket::select with the array as the check_read parameter. To check your sockets for writability, use the check_write parameter. For detecting error conditions, use check_error. After calling xtd::net::sockets::socket::select, the array will be filled with only those sockets that satisfy the conditions.
If you are in a listening state, readability means that a call to xtd::net::sockets::socket::accept will succeed without blocking. If you have already accepted the connection, readability means that data is available for reading. In these cases, all receive operations will succeed without blocking. Readability can also indicate whether the remote xtd::net::sockets::socket has shut down the connection; in that case a call to xtd::net::sockets::socket::receive will return immediately, with zero bytes returned.
xtd::net::sockets::socket::select returns when at least one of the sockets of interest (the sockets in the check_read, check_write, and check_error lists) meets its specified criteria, or the microseconds parameter is exceeded, whichever comes first. Setting microseconds to -1 specifies an infinite time-out.
If you make a nonblocking call to xtd::net::sockets::socket::connect, writability means that you have connected successfully. If you already have a connection established, writability means that all send operations will succeed without blocking.
If you have made a non-blocking call to xtd::net::sockets::socket::connect, the check_error parameter identifies sockets that have not connected successfully.
Use the xtd::net::sockets::socket::poll method if you only want to determine the status of a single xtd::net::sockets::socket.
Note
This method cannot detect certain kinds of connection problems, such as a broken network cable, or that the remote host was shut down ungracefully. You must attempt to send or receive data to detect these kinds of errors.
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

◆ equals() [1/2]

virtual bool xtd::object::equals ( const object obj) const
virtualnoexcept

Determines whether the specified object is equal to the current object.

Parameters
objThe object to compare with the current object.
Returns
true if the specified object is equal to the current object. otherwise, false.
Examples
The following code example compares the current instance with another object.
#include <xtd/console>
using namespace xtd;
auto main() -> int {
auto object1 = new_ptr<object>();
auto object2 = new_ptr<object>();
auto object3 = object2;
console::write_line(object1->equals(*object3));
console::write_line(*object1 == *object3);
object3 = object1;
console::write_line(object1->equals(*object3));
console::write_line(*object1 == *object3);
}
// This code produces the following output :
//
// false
// false
// true
// true
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10

Reimplemented from xtd::object.

◆ equals() [2/2]

template<typename object_a_t , typename object_b_t >
static bool xtd::object::equals ( const object_a_t &  object_a,
const object_b_t &  object_b 
)
inlinestaticnoexcept

Determines whether the specified object instances are considered equal.

Parameters
object_aThe first object to compare.
object_bThe second object to compare.
Returns
true if object_a is the same instance as object_b or if both are null references or if object_a(object_b) returns true. otherwise, false.
Examples
The following code example compares different objects.
#include <xtd/console>
using namespace xtd;
auto main() -> int {
string s1 = "Tom";
string s2 = "Carol";
console::write_line("object::equals(\"{0}\", \"{1}\") => {2}", s1, s2, object::equals(s1, s2));
s1 = "Tom";
s2 = "Tom";
console::write_line("object::equals(\"{0}\", \"{1}\") => {2}", s1, s2, object::equals(s1, s2));
s1 = "";
s2 = "Tom";
console::write_line("object::equals(\"{0}\", \"{1}\") => {2}", s1, s2, object::equals(s1, s2));
s1 = "Carol";
s2 = "";
console::write_line("object::equals(\"{0}\", \"{1}\") => {2}", s1, s2, object::equals(s1, s2));
s1 = "";
s2 = "";
console::write_line("object::equals(\"{0}\", \"{1}\") => {2}", s1, s2, object::equals(s1, s2));
}
// This code produces the following output :
//
// object::equals("Tom", "Carol") => false
// object::equals("Tom", "Tom") => true
// object::equals("", "Tom") => false
// object::equals("Carol", "") => false
// object::equals("", "") => true
virtual bool equals(const object &obj) const noexcept
Determines whether the specified object is equal to the current object.

The documentation for this class was generated from the following file: