xtd - Reference Guide  0.1.2
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
Loading...
Searching...
No Matches
socket.h
Go to the documentation of this file.
1
4#pragma once
5
6#include <memory>
7#include "../../core_export.h"
8#include "../../argument_exception.h"
9#include "../../async_callback.h"
10#include "../../iasync_result.h"
11#include "../../not_implemented_exception.h"
12#include "../../not_supported_exception.h"
13#include "../../object.h"
14#include "../../types.h"
15#include "../../ustring.h"
16#include "../end_point.h"
17#include "../ip_address.h"
18#include "address_family.h"
19#include "io_control_code.h"
21#include "ip_protection_level.h"
22#include "linger_option.h"
23#include "multicast_option.h"
25#include "protocol_type.h"
26#include "select_mode.h"
27#include "socket_error.h"
28#include "socket_flags.h"
29#include "socket_information.h"
30#include "socket_option_level.h"
31#include "socket_option_name.h"
32#include "socket_shutdown.h"
33#include "socket_type.h"
34
36namespace xtd {
38 namespace net {
40 namespace sockets {
42 class socket_async_event_args;
44
64 class async_result_socket : public xtd::object, public xtd::iasync_result {
65 public:
66 async_result_socket(std::any async_state) : async_state_(async_state) {}
67 std::any async_state() const noexcept override {return async_state_;}
68 std::shared_mutex& async_mutex() override {return async_mutex_;}
69 bool completed_synchronously() const noexcept override {return false;}
70 bool is_completed() const noexcept override {return is_completed_;};
71
72 std::any async_state_;
73 bool is_completed_ = false;
74 std::shared_mutex async_mutex_;
76 std::exception_ptr exception_;
77 };
78
79 class async_result_accept : public async_result_socket {
80 public:
81 async_result_accept(std::any async_state) : async_result_socket(async_state) {}
82 std::any socket_;
83 };
84
85 class async_result_connect : public async_result_socket {
86 public:
87 async_result_connect(std::any async_state) : async_result_socket(async_state) {}
88 };
89
90 class async_result_disconnect : public async_result_socket {
91 public:
92 async_result_disconnect(std::any async_state) : async_result_socket(async_state) {}
93 };
94
95 class async_result_receive : public async_result_socket {
96 public:
97 async_result_receive(std::any async_state) : async_result_socket(async_state) {}
98 size_t number_of_bytes_received_ = 0;
99 };
100
101 class async_result_receive_from : public async_result_socket {
102 public:
103 async_result_receive_from(std::any async_state) : async_result_socket(async_state) {}
104 std::shared_ptr<xtd::net::end_point> end_point_;
105 size_t number_of_bytes_received_ = 0;
106 };
107
108 class async_result_receive_message_from : public async_result_socket {
109 public:
110 async_result_receive_message_from(std::any async_state) : async_result_socket(async_state) {}
111 std::shared_ptr<xtd::net::end_point> end_point_;
113 size_t number_of_bytes_received_ = 0;
114 xtd::net::sockets::ip_packet_information ip_packet_information_;
115 };
116
117 class async_result_send : public async_result_socket {
118 public:
119 async_result_send(std::any async_state) : async_result_socket(async_state) {}
120 size_t number_of_bytes_sent_ = 0;
121 };
122
123 class async_result_send_to : public async_result_socket {
124 public:
125 async_result_send_to(std::any async_state) : async_result_socket(async_state) {}
126 size_t number_of_bytes_sent_ = 0;
127 };
128
129 public:
132
137 socket(intptr_t handle);
157
159 socket(socket&&) = default;
160 socket(const socket&) = default;
161 ~socket();
162 socket& operator=(const socket&) = default;
163 friend std::ostream& operator <<(std::ostream& os, const socket& mo) noexcept {return os << mo.to_string();}
164 bool operator==(const socket& s) const {return data_ == s.data_;};
165 bool operator!=(const socket& s) const {return !operator==(s);};
167
172
177 size_t available() const;
178
186 bool blocking() const;
195 socket& blocking(bool value);
196
202 bool connected() const noexcept;
203
210 bool dont_fragment() const;
218 socket& dont_fragment(bool value);
219
226 bool dual_mode() const;
234 socket& dual_mode(bool value);
235
243 bool enable_broadcast() const;
252 socket& enable_broadcast(bool value);
253
262 bool exclusive_address_use() const;
273 socket& exclusive_address_use(bool value);
274
277 intptr_t handle() const noexcept;
278
282 bool is_bound() const noexcept;
283
301 xtd::net::sockets::linger_option linger_state() const;
320 socket& linger_state(const xtd::net::sockets::linger_option& value);
321
327 std::shared_ptr<xtd::net::end_point> local_end_point() const;
328
337 bool multicast_loopback() const;
347 socket& multicast_loopback(bool value);
348
357 bool no_delay() const;
367 socket& no_delay(bool value);
368
372 static bool os_supports_ip_v4() noexcept;
373
377 static bool os_supports_ip_v6() noexcept;
378
382 xtd::net::sockets::protocol_type protocol_type() const noexcept;
383
390 size_t receive_buffer_size() const;
398 socket& receive_buffer_size(size_t value);
399
406 int32_t receive_timeout() const;
415 socket& receive_timeout(int32_t value);
416
422 std::shared_ptr<xtd::net::end_point> remote_end_point() const;
423
430 size_t send_buffer_size() const;
438 socket& send_buffer_size(size_t value);
439
446 int32_t send_timeout() const;
455 socket& send_timeout(int32_t value);
456
460 xtd::net::sockets::socket_type socket_type() const noexcept;
461
471 byte_t ttl() const;
482 socket& ttl(byte_t value);
483
494 socket accept();
495
513 bool accept_async(xtd::net::sockets::socket_async_event_args& e);
514
529 std::shared_ptr<xtd::iasync_result> begin_accept(xtd::async_callback callback, const std::any& state);
530
546 template<typename end_point_t>
547 std::shared_ptr<xtd::iasync_result> begin_connect(const end_point_t& remote_end_point, xtd::async_callback callback, const std::any& state) {
548 return begin_connect_(std::make_shared<end_point_t>(remote_end_point), callback, state);
549 }
563 std::shared_ptr<xtd::iasync_result> begin_connect(const xtd::net::ip_address& address, uint16_t port, xtd::async_callback callback, const std::any& state);
577 std::shared_ptr<xtd::iasync_result> begin_connect(const std::vector<xtd::net::ip_address>& addresses, uint16_t port, xtd::async_callback callback, const std::any& state);
591 std::shared_ptr<xtd::iasync_result> begin_connect(const xtd::ustring& host, uint16_t port, xtd::async_callback callback, const std::any& state);
592
603 std::shared_ptr<xtd::iasync_result> begin_disconnect(bool reuse_socket, xtd::async_callback callback, const std::any& state);
604
622 std::shared_ptr<xtd::iasync_result> begin_receive(std::vector<byte_t>& buffer, size_t offset, size_t size, xtd::net::sockets::socket_flags socket_flags, xtd::async_callback callback, const std::any& state);
641 std::shared_ptr<xtd::iasync_result> begin_receive(std::vector<byte_t>& 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);
642
665 std::shared_ptr<xtd::iasync_result> begin_receive_from(std::vector<byte_t>& 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);
666
684 std::shared_ptr<xtd::iasync_result> begin_receive_message_from(std::vector<byte_t>& 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);
685
706 std::shared_ptr<xtd::iasync_result> begin_send(const std::vector<byte_t>& buffer, size_t offset, size_t size, xtd::net::sockets::socket_flags socket_flags, xtd::async_callback callback, const std::any& state);
728 std::shared_ptr<xtd::iasync_result> begin_send(const std::vector<byte_t>& 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);
729
750 std::shared_ptr<xtd::iasync_result> begin_send_to(const std::vector<byte_t>& 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);
751
763 template<typename end_point_t>
764 void bind(const end_point_t& local_end_point) {
765 bind_(std::make_shared<end_point_t>(local_end_point));
766 }
767
773 void close();
774
784 template<typename end_point_t>
785 void connect(const end_point_t& remote_end_point) {
786 connect_(std::make_shared<end_point_t>(remote_end_point));
787 }
788
799 void connect(const xtd::net::ip_address& address, uint16_t port);
800
812 void connect(const std::vector<xtd::net::ip_address>& addresses, uint16_t port);
813
824 void connect(const xtd::ustring& host, uint16_t port);
825
834 void disconnect(bool reuse_socket);
835
845 socket end_accept(std::shared_ptr<xtd::iasync_result> async_result);
846
856 void end_connect(std::shared_ptr<xtd::iasync_result> async_result);
857
865 void end_disconnect(std::shared_ptr<xtd::iasync_result> async_result);
866
881 size_t end_receive(std::shared_ptr<xtd::iasync_result> async_result);
896 size_t end_receive(std::shared_ptr<xtd::iasync_result> async_result, xtd::net::sockets::socket_error& error_code);
897
909 size_t end_receive_from(std::shared_ptr<xtd::iasync_result> async_result, std::shared_ptr<xtd::net::end_point>& end_point);
910
924 size_t end_receive_message_from(std::shared_ptr<xtd::iasync_result> async_result, xtd::net::sockets::socket_flags& socket_flags, std::shared_ptr<xtd::net::end_point>& end_point, xtd::net::sockets::ip_packet_information& ip_packet_information);
925
940 size_t end_send(std::shared_ptr<xtd::iasync_result> async_result);
956 size_t end_send(std::shared_ptr<xtd::iasync_result> async_result, xtd::net::sockets::socket_error& error_code);
957
969 size_t end_send_to(std::shared_ptr<xtd::iasync_result> async_result);
970
979 size_t get_raw_socket_option(int32_t socket_option_level, int32_t socket_option_name, intptr_t option_value, size_t size_option_value) const;
980
1014
1022 size_t io_control(int32_t io_control_code, std::vector<uint8_t>& option_in_value, std::vector<uint8_t>& option_out_value);
1030 size_t io_control(xtd::net::sockets::io_control_code io_control_code, std::vector<uint8_t>& option_in_value, std::vector<uint8_t>& option_out_value);
1031
1040 void listen(size_t backlog);
1041
1050 void listen();
1051
1065 bool poll(int32_t micro_seconds, xtd::net::sockets::select_mode mode);
1066
1079 size_t receive(std::vector<byte_t>& buffer);
1080
1094 size_t receive(std::vector<byte_t>& buffer, xtd::net::sockets::socket_flags socket_flags);
1095
1111 size_t receive(std::vector<byte_t>& buffer, size_t size, xtd::net::sockets::socket_flags socket_flags);
1112
1128 size_t receive(std::vector<byte_t>& buffer, size_t offset, size_t size, xtd::net::sockets::socket_flags socket_flags);
1129
1145 size_t receive(std::vector<byte_t>& buffer, size_t offset, size_t size, xtd::net::sockets::socket_flags socket_flags, xtd::net::sockets::socket_error& error);
1146
1162 size_t receive_from(std::vector<byte_t>& buffer, xtd::net::end_point& remote_end_point);
1163
1180 size_t receive_from(std::vector<byte_t>& buffer, xtd::net::sockets::socket_flags socket_flags, xtd::net::end_point& remote_end_point);
1181
1200 size_t receive_from(std::vector<byte_t>& buffer, size_t size, xtd::net::sockets::socket_flags socket_flags, xtd::net::end_point& remote_end_point);
1201
1220 size_t receive_from(std::vector<byte_t>& buffer, size_t offset, size_t size, xtd::net::sockets::socket_flags socket_flags, xtd::net::end_point& remote_end_point);
1221
1223
1239 static size_t select(std::vector<socket>& check_read,std::vector<socket>& check_write, std::vector<socket>& check_error, int32_t microseconds);
1240
1253 size_t send(const std::vector<byte_t>& buffer);
1254
1268 size_t send(const std::vector<byte_t>& buffer, xtd::net::sockets::socket_flags socket_flags);
1269
1285 size_t send(const std::vector<byte_t>& buffer, size_t size, xtd::net::sockets::socket_flags socket_flags);
1286
1303 size_t send(const std::vector<byte_t>& buffer, size_t offset, size_t size, xtd::net::sockets::socket_flags socket_flags);
1304
1320 size_t send(const std::vector<byte_t>& buffer, size_t offset, size_t size, xtd::net::sockets::socket_flags socket_flags, xtd::net::sockets::socket_error& error_code);
1321
1334 size_t send_to(const std::vector<byte_t>& buffer, const xtd::net::end_point& remote_end_point);
1348 size_t send_to(const std::vector<byte_t>& buffer, xtd::net::sockets::socket_flags socket_flags, const xtd::net::end_point& remote_end_point);
1364 size_t send_to(const std::vector<byte_t>& buffer, size_t size, xtd::net::sockets::socket_flags socket_flags, const xtd::net::end_point& remote_end_point);
1381 size_t send_to(const std::vector<byte_t>& buffer, size_t offset, size_t size, xtd::net::sockets::socket_flags socket_flags, const xtd::net::end_point& remote_end_point);
1382
1395
1426
1488
1499 void set_raw_socket_option(int32_t socket_option_level, int32_t socket_option_name, intptr_t option_value, size_t option_value_size);
1500
1521
1522 private:
1523 static xtd::net::sockets::socket_error get_last_error_();
1524 std::shared_ptr<xtd::iasync_result> begin_connect_(std::shared_ptr<xtd::net::end_point> remote_end_point, xtd::async_callback callback, const std::any& state);
1525 void bind_(std::shared_ptr<xtd::net::end_point> local_end_point);
1526 void connect_(std::shared_ptr<xtd::net::end_point> remote_end_point);
1527 struct data;
1528
1529 std::shared_ptr<data> data_;
1530 };
1531 }
1532 }
1533}
Contains xtd::net::sockets::address_family enum.
Represents the status of an asynchronous operation.
Definition iasync_result.h:21
Identifies a network address. This is an abstract class.
Definition end_point.h:24
Provides an Internet Protocol (IP) address.
Definition ip_address.h:30
Gets the network interface information that is associated with a call to xtd::net::sockets::socket::r...
Definition ip_packet_information.h:28
Contains option values for joining an IPv6 multicast group.
Definition ip_v6_multicast_option.h:24
Specifies whether a xtd::net::sockets::socket will remain connected after a call to the xtd::net::soc...
Definition linger_option.h:26
Contains IPAddress values used to join and drop multicast groups.
Definition multicast_option.h:31
Represents an asynchronous socket operation.
Definition socket_async_event_args.h:46
Encapsulates the information that is necessary to duplicate a xtd::net::sockets::socket.
Definition socket_information.h:25
Implements the Berkeley sockets interface.
Definition socket.h:63
void bind(const end_point_t &local_end_point)
Associates a xtd::net::sockets::socket with a local endpoint.
Definition socket.h:764
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_multi...
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_o...
size_t send(const std::vector< byte_t > &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,...
void set_socket_option(xtd::net::sockets::socket_option_level socket_option_level, xtd::net::sockets::socket_option_name socket_option_name, int32_t option_value)
Sets the specified xtd::net::sockets::socket option to the specified integer value.
size_t receive_from(std::vector< byte_t > &buffer, xtd::net::end_point &remote_end_point)
Receives data from a bound xtd::net::sockets::socket into a receive buffer.
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,...
std::shared_ptr< xtd::iasync_result > begin_receive_from(std::vector< byte_t > &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.
static size_t select(std::vector< socket > &check_read, std::vector< socket > &check_write, std::vector< socket > &check_error, int32_t microseconds)
Determines the status of one or more sockets.
size_t send(const std::vector< byte_t > &buffer)
Sends data to a connected xtd::net::sockets::socket.
size_t receive_from(std::vector< byte_t > &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 io_control(xtd::net::sockets::io_control_code io_control_code, std::vector< uint8_t > &option_in_value, std::vector< uint8_t > &option_out_value)
Sets low-level operating modes for the xtd::net::sockets::socket using xtd::net::sockets::io_control_...
void set_raw_socket_option(int32_t socket_option_level, int32_t socket_option_name, intptr_t option_value, size_t option_value_size)
Sets a socket option value using platform-specific level and name identifiers.
void listen(size_t backlog)
Places a xtd::net::sockets::socket in a listening state.
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.
socket end_accept(std::shared_ptr< xtd::iasync_result > async_result)
Asynchronously accepts an incoming connection attempt and creates a new xtd::net::sockets::socket::so...
std::shared_ptr< xtd::iasync_result > begin_connect(const std::vector< xtd::net::ip_address > &addresses, uint16_t port, xtd::async_callback callback, const std::any &state)
Begins an asynchronous request for a remote host connection. The host is specified by an xtd::net::ip...
size_t end_receive(std::shared_ptr< xtd::iasync_result > async_result, xtd::net::sockets::socket_error &error_code)
Ends a pending asynchronous read.
size_t get_raw_socket_option(int32_t socket_option_level, int32_t socket_option_name, intptr_t option_value, size_t size_option_value) const
Gets a socket option value using platform-specific level and name identifiers.
std::shared_ptr< xtd::iasync_result > begin_disconnect(bool reuse_socket, xtd::async_callback callback, const std::any &state)
Begins an asynchronous request to disconnect from a remote endpoint.
size_t send(const std::vector< byte_t > &buffer, xtd::net::sockets::socket_flags socket_flags)
Sends data to a connected xtd::net::sockets::socket using the specified xtd::net::sockets::socket_fla...
size_t io_control(int32_t io_control_code, std::vector< uint8_t > &option_in_value, std::vector< uint8_t > &option_out_value)
Sets low-level operating modes for the xtd::net::sockets::socket using numerical control codes.
std::shared_ptr< xtd::iasync_result > begin_send_to(const std::vector< byte_t > &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.
size_t end_receive(std::shared_ptr< xtd::iasync_result > async_result)
Ends a pending asynchronous read.
void end_disconnect(std::shared_ptr< xtd::iasync_result > async_result)
Ends a pending asynchronous disconnect request.
size_t end_receive_message_from(std::shared_ptr< xtd::iasync_result > async_result, xtd::net::sockets::socket_flags &socket_flags, std::shared_ptr< 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 ...
int32_t 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::address_family address_family() const noexcept
Gets the address family of the xtd::net::sockets::socket.
void shutdown(xtd::net::sockets::socket_shutdown how)
Disables sends and receives on a xtd::net::sockets::socket.
void connect(const std::vector< xtd::net::ip_address > &addresses, uint16_t port)
Establishes a connection to a remote host. The host is specified by an array of IP addresses and a po...
size_t send(const std::vector< byte_t > &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,...
void set_socket_option(xtd::net::sockets::socket_option_name socket_option_name, xtd::net::sockets::multicast_option option_value)
Sets the linger xtd::net::sockets::socket option to the specified integer value.
size_t end_send(std::shared_ptr< xtd::iasync_result > async_result, xtd::net::sockets::socket_error &error_code)
Ends a pending asynchronous send.
void end_connect(std::shared_ptr< xtd::iasync_result > async_result)
Ends a pending asynchronous connection request.
std::shared_ptr< xtd::iasync_result > begin_send(const std::vector< byte_t > &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.
void connect(const xtd::net::ip_address &address, uint16_t port)
Establishes a connection to a remote host. The host is specified by an IP address and a port number.
std::shared_ptr< xtd::iasync_result > begin_receive(std::vector< byte_t > &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.
size_t receive(std::vector< byte_t > &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 offs...
size_t receive(std::vector< byte_t > &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::...
std::shared_ptr< xtd::iasync_result > begin_connect(const xtd::net::ip_address &address, uint16_t port, xtd::async_callback callback, const std::any &state)
Begins an asynchronous request for a remote host connection. The host is specified by an xtd::net::ip...
void close()
Closes the xtd::net::sockets::socket connection and releases all associated resources.
void connect(const end_point_t &remote_end_point)
Establishes a connection to a remote host.
Definition socket.h:785
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.
bool poll(int32_t micro_seconds, xtd::net::sockets::select_mode mode)
Determines the status of the xtd::net::sockets::socket.
void disconnect(bool reuse_socket)
Closes the socket connection and allows reuse of the socket.
void set_socket_option(xtd::net::sockets::linger_option option_value)
Sets the linger xtd::net::sockets::socket option to the specified integer value.
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 ...
size_t end_receive_from(std::shared_ptr< xtd::iasync_result > async_result, std::shared_ptr< xtd::net::end_point > &end_point)
Ends a pending asynchronous read from a specific endpoint.
size_t send_to(const std::vector< byte_t > &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 loca...
size_t receive(std::vector< byte_t > &buffer)
Receives data from a bound xtd::net::sockets::socket into a receive buffer.
size_t receive_from(std::vector< byte_t > &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.
socket()
Initializes a new instance of the xtd::net::sockets::socket class.
void listen()
Places a xtd::net::sockets::socket in a listening state.
size_t send_to(const std::vector< byte_t > &buffer, const xtd::net::end_point &remote_end_point)
Sends data to the specified endpoint.
size_t send_to(const std::vector< byte_t > &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.
void connect(const xtd::ustring &host, uint16_t port)
Establishes a connection to a remote host. The host is specified by a host name and a port number.
std::shared_ptr< xtd::iasync_result > begin_send(const std::vector< byte_t > &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.
std::shared_ptr< xtd::iasync_result > begin_connect(const xtd::ustring &host, uint16_t port, xtd::async_callback callback, const std::any &state)
Begins an asynchronous request for a remote host connection. The host is specified by a host name and...
std::shared_ptr< xtd::iasync_result > begin_receive(std::vector< byte_t > &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.
void set_socket_option(xtd::net::sockets::socket_option_name socket_option_name, xtd::net::sockets::ip_v6_multicast_option option_value)
Sets the linger xtd::net::sockets::socket option to the specified integer value.
size_t receive(std::vector< byte_t > &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 offs...
size_t receive_from(std::vector< byte_t > &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.
void set_ip_protection_level(xtd::net::sockets::ip_protection_level level)
Sets the IP protection level on a 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...
size_t send_to(const std::vector< byte_t > &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::s...
size_t receive(std::vector< byte_t > &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 ...
socket(intptr_t handle)
Initializes a new instance of the xtd::net::sockets::socket class for the specified socket handle.
std::shared_ptr< xtd::iasync_result > begin_receive_message_from(std::vector< byte_t > &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...
size_t send(const std::vector< byte_t > &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,...
size_t end_send(std::shared_ptr< xtd::iasync_result > async_result)
Ends a pending asynchronous send.
size_t end_send_to(std::shared_ptr< xtd::iasync_result > async_result)
Ends a pending asynchronous send to a specific location.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.h:26
virtual xtd::ustring to_string() const noexcept
Returns a std::string that represents the current object.
Represents text as a sequence of UTF-8 code units.
Definition ustring.h:48
#define core_export_
Define shared library export.
Definition core_export.h:13
size_t size
Represents a size of any object in bytes.
Definition types.h:171
socket_error
Defines error codes for the xtd::net::sockets::socket class.
Definition socket_error.h:24
address_family
Specifies the addressing scheme that an instance of the xtd::net::sockets::socket class can use.
Definition address_family.h:24
io_control_code
Specifies the IO control codes supported by the xtd::net::sockets::socket::io_control method.
Definition io_control_code.h:24
socket_option_level
Defines socket option levels for the xtd::net::sockets::socket::set_socket_option and xtd::net::socke...
Definition socket_option_level.h:25
delegate< void(std::shared_ptr< xtd::iasync_result > ar)> async_callback
References a method to be called when a corresponding asynchronous operation completes.
Definition async_callback.h:18
socket_option_name
Defines configuration option names.
Definition socket_option_name.h:25
ip_protection_level
A value that enables restriction of an IPv6 socket to a specified scope, such as addresses with the s...
Definition ip_protection_level.h:25
protocol_type
Specifies the protocols that the xtd::net::sockets::socket class supports.
Definition protocol_type.h:24
socket_flags
Specifies socket send and receive behaviors. This enumeration has a flags attribute that allows a bit...
Definition socket_flags.h:24
select_mode
Defines the polling modes for the xtd::net::sockets::socket::poll method.
Definition select_mode.h:25
socket_type
Specifies the type of socket that an instance of the xtd::net::sockets::socket class represents.
Definition socket_type.h:26
socket_shutdown
Defines constants that are used by the xtd::net::sockets::socket::shutdown method.
Definition socket_shutdown.h:25
@ success
Operation successful.
@ receive_message_from
A socket receive_message_from operation.
@ s
The S key.
Contains xtd::net::sockets::io_control_code enum.
Contains xtd::net::sockets::ip_packet_information class.
Contains xtd::net::sockets::ip_protection_level enum.
Contains xtd::net::sockets::ip_v6_multicast_option class.
Contains xtd::net::sockets::linger_option class.
Contains xtd::net::sockets::multicast_option class.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition system_report.h:17
Contains xtd::net::sockets::protocol_type enum.
Contains xtd::net::sockets::select_mode enum.
Contains xtd::net::sockets::socket_error enum.
Contains xtd::net::sockets::socket_flags enum.
Contains xtd::net::sockets::socket_information class.
Contains xtd::net::sockets::socket_option_level enum.
Contains xtd::net::sockets::socket_option_name enum.
Contains xtd::net::sockets::socket_shutdown enum.
Contains xtd::net::sockets::socket_type enum.