xtd 0.2.0
Loading...
Searching...
No Matches
udp_client.hpp
Go to the documentation of this file.
1
4#pragma once
5#include "socket.hpp"
6#include "../ip_end_point.hpp"
9#include "../../object.hpp"
10#include "../../string.hpp"
11
13namespace xtd {
15 namespace net {
17 namespace sockets {
45 class core_export_ udp_client : public xtd::object, public xtd::iequatable<udp_client> {
46 class async_result_socket : public xtd::object, public xtd::iasync_result {
47 public:
48 explicit async_result_socket(const xtd::any_object& async_state) : async_state_(async_state) {}
49 xtd::any_object async_state() const noexcept override {return async_state_;}
50 xtd::threading::wait_handle& async_wait_handle() noexcept override {return async_event_;}
51 bool completed_synchronously() const noexcept override {return false;}
52 bool is_completed() const noexcept override {return is_completed_;};
53
54 xtd::any_object async_state_;
55 bool is_completed_ = false;
58 std::exception_ptr exception_;
59 };
60
61 class async_result_receive : public async_result_socket {
62 public:
63 explicit async_result_receive(const xtd::any_object& async_state) : async_result_socket(async_state) {}
65 xtd::net::ip_end_point remote_end_point_;
66 };
67
68 class async_result_send : public async_result_socket {
69 public:
70 explicit async_result_send(const xtd::any_object& async_state) : async_result_socket(async_state) {}
71 xtd::size number_of_bytes_sent_ = 0;
72 };
73
74 struct data;
75
76 public:
78
99 explicit udp_client(const xtd::net::ip_end_point& local_end_point);
127
129 udp_client(udp_client&&) = default;
130 udp_client(const udp_client&) = default;
131 ~udp_client();
132 auto operator =(const udp_client&) -> udp_client& = default;
133 auto operator =(udp_client&&) -> udp_client& = default;
135
137
146 [[nodiscard]] auto available() const -> xtd::size;
147
151 [[nodiscard]] auto client() const noexcept -> xtd::net::sockets::socket;
156 auto client(const xtd::net::sockets::socket& value) noexcept -> udp_client&;
157
164 [[nodiscard]] auto dont_fragment() const -> bool;
172 auto dont_fragment(bool value) -> udp_client&;
173
180 [[nodiscard]] auto enable_broadcast() const -> bool;
188 auto enable_broadcast(bool value) -> udp_client&;
189
197 [[nodiscard]] auto exclusive_address_use() const -> bool;
206 auto exclusive_address_use(bool value) -> udp_client&;
207
214 [[nodiscard]] auto multicast_loopback() const -> bool;
222 auto multicast_loopback(bool value) -> udp_client&;
223
230 [[nodiscard]] auto ttl() const -> xtd::byte;
238 auto ttl(xtd::byte value) -> udp_client&;
240
242
252 auto allow_nat_traversal(bool allowed) -> void;
253
260 auto begin_receive(xtd::async_callback callback, const xtd::any_object& state) -> xtd::sptr<xtd::iasync_result>;
261
272 auto begin_send(const xtd::array<xtd::byte>& dgram, xtd::size bytes, const xtd::string& hostname, uint16 port, xtd::async_callback callback, const xtd::any_object& state) -> xtd::sptr<xtd::iasync_result>;
273
283 auto begin_send(const xtd::array<xtd::byte>& dgram, xtd::size bytes, const xtd::net::ip_end_point& end_point, xtd::async_callback callback, const xtd::any_object& state) -> xtd::sptr<xtd::iasync_result>;
292 auto begin_send(const xtd::array<xtd::byte>& dgram, xtd::size bytes, xtd::async_callback callback, const xtd::any_object& state) -> xtd::sptr<xtd::iasync_result>;
293
298 auto close() -> void;
299
310 auto connect(const xtd::net::ip_end_point& end_point) -> void;
322 auto connect(const xtd::net::ip_address& ip_address, uint16 port) -> void;
334 auto connect(const xtd::string& hostname, uint16 port) -> void;
335
342 auto drop_multicast_group(const xtd::net::ip_address& multicast_address) -> void;
350 auto drop_multicast_group(const xtd::net::ip_address& multicast_address, uint32 if_index) -> void;
351
362 auto end_receive(xtd::sptr<xtd::iasync_result> async_result, xtd::net::ip_end_point& remote_end_point) -> xtd::array<xtd::byte>;
363
374
378 [[nodiscard]] auto equals(const object& obj) const noexcept -> bool override;
382 [[nodiscard]] auto equals(const udp_client& other) const noexcept -> bool override;
383
396 auto join_multicast_group(const xtd::net::ip_address& multicast_address) -> void;
409 auto join_multicast_group(uint32 if_index, const xtd::net::ip_address& multicast_address) -> void;
422 auto join_multicast_group(const xtd::net::ip_address& multicast_address, xtd::byte ttl) -> void;
432 auto join_multicast_group(const xtd::net::ip_address& multicast_address, const xtd::net::ip_address& local_address) -> void;
433
444 [[nodiscard]] auto receive(xtd::net::ip_end_point& remote_end_point) -> xtd::array<xtd::byte>;
445
458 auto send(const xtd::array<xtd::byte>& dgram, xtd::size bytes, const xtd::string& hostname, uint16 port) -> xtd::size;
470 auto send(const xtd::array<xtd::byte>& dgram, xtd::size bytes, const xtd::net::ip_end_point& end_point) -> xtd::size;
480 auto send(const xtd::array<xtd::byte>& dgram, xtd::size bytes) -> xtd::size;
482
483 protected:
485
490 [[nodiscard]] auto active() const noexcept -> bool;
495 auto active(bool value) noexcept -> udp_client&;
497
498 private:
500
501 xtd::sptr<data> data_;
502 };
503 }
504 }
505}
Represent a polymorphic wrapper capable of holding any type.
Definition any_object.hpp:29
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:64
Represents the status of an asynchronous operation.
Definition iasync_result.hpp:25
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.hpp:23
Identifies a network address. This is an abstract class.
Definition end_point.hpp:27
Provides an Internet Protocol (IP) address.
Definition ip_address.hpp:42
Represents a network endpoint as an IP address and a port number.
Definition ip_end_point.hpp:28
Implements the Berkeley sockets interface.
Definition socket.hpp:77
udp_client(uint16 port, xtd::net::sockets::address_family addressFamily)
Initializes a new instance of the xtd::net::sockets::udp_client class and binds it to the local port ...
auto begin_receive(xtd::async_callback callback, const xtd::any_object &state) -> xtd::sptr< xtd::iasync_result >
xtd::net::sockets::udp_client::receives a datagram from a remote host asynchronously.
auto client() const noexcept -> xtd::net::sockets::socket
Gets the underlying network xtd::net::sockets::socket.
auto dont_fragment() const -> bool
Gets a boolean value that specifies whether the xtd::net::sockets::udp_client allows Internet Protoco...
auto available() const -> xtd::size
Gets the amount of data received from the network that is available to read.
auto enable_broadcast() const -> bool
Gets a boolean value that specifies whether the xtd::net::sockets::udp_client may send or receive bro...
auto drop_multicast_group(const xtd::net::ip_address &multicast_address) -> void
Leaves a multicast group.
udp_client(uint16 port)
Initializes a new instance of the xtd::net::sockets::udp_client class and binds it to the local port ...
auto active() const noexcept -> bool
Gets a value that indicates whether a connection has been made.
udp_client(const xtd::net::ip_end_point &local_end_point)
Initializes a new instance of the xtd::net::sockets::udp_client class and binds it to the specified l...
auto send(const xtd::array< xtd::byte > &dgram, xtd::size bytes, const xtd::string &hostname, uint16 port) -> xtd::size
xtd::net::sockets::udp_client::sends a UDP datagram to a specified port on a specified remote host.
auto receive(xtd::net::ip_end_point &remote_end_point) -> xtd::array< xtd::byte >
Returns a UDP datagram that was sent by a remote host.
auto multicast_loopback() const -> bool
Gets a boolean value that specifies whether outgoing multicast packets are delivered to the sending a...
auto allow_nat_traversal(bool allowed) -> void
Enables or disables Network Address Translation (NAT) traversal on a xtd::net::sockets::udp_client in...
auto equals(const object &obj) const noexcept -> bool override
Determines whether the specified object is equal to the current object.
auto ttl() const -> xtd::byte
Gets a value that specifies the Time to Live (TTL) value of Internet Protocol (IP) packets sent by th...
auto end_receive(xtd::sptr< xtd::iasync_result > async_result, xtd::net::ip_end_point &remote_end_point) -> xtd::array< xtd::byte >
Ends a pending asynchronous receive.
auto close() -> void
Closes the UDP connection.
udp_client(const xtd::string &hostname, uint16 port)
Initializes a new instance of the xtd::net::sockets::udp_client class and establishes a default remot...
auto end_send(xtd::sptr< xtd::iasync_result > async_result) -> xtd::size
Ends a pending asynchronous send.
auto join_multicast_group(const xtd::net::ip_address &multicast_address) -> void
Adds a xtd::net::sockets::udp_client to a multicast group.
auto exclusive_address_use() const -> bool
Gets a boolean value that specifies whether the xtd::net::sockets::udp_client allows only one client ...
udp_client()
Initializes a new instance of the xtd::net::sockets::udp_client class.
auto begin_send(const xtd::array< xtd::byte > &dgram, xtd::size bytes, const xtd::string &hostname, uint16 port, xtd::async_callback callback, const xtd::any_object &state) -> xtd::sptr< xtd::iasync_result >
xtd::net::sockets::udp_client::sends a datagram to a destination asynchronously. The destination is s...
auto connect(const xtd::net::ip_end_point &end_point) -> void
Establishes a default remote host using the specified network endpoint.
udp_client(xtd::net::sockets::address_family address_Family)
Initializes a new instance of the xtd::net::sockets::udp_client class.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:45
Represents a thread synchronization event that, when signaled, must be reset manually....
Definition manual_reset_event.hpp:35
Encapsulates operating system specific objects that wait for exclusive access to shared resources.
Definition wait_handle.hpp:52
xtd::delegate< void(async_result ar)> async_callback
References a method to be called when a corresponding asynchronous operation completes.
Definition delegate.hpp:39
#define core_export_
Define shared library export.
Definition core_export.hpp:13
xtd::basic_string< char > string
Represents text as a sequence of UTF-8 code units.
Definition __string_definitions.hpp:43
std::uint32_t uint32
Represents a 32-bit unsigned integer.
Definition uint32.hpp:23
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
xtd::shared_ptr_object< type_t > sptr
The xtd::sptr object is a shared pointer.
Definition sptr.hpp:25
std::uint16_t uint16
Represents a 16-bit unsigned integer.
Definition uint16.hpp:23
xtd::sptr< xtd::iasync_result > async_result
Represents the status of an asynchronous operation.
Definition async_result.hpp:19
socket_error
Defines error codes for the xtd::net::sockets::socket class.
Definition socket_error.hpp:30
address_family
Specifies the addressing scheme that an instance of the xtd::net::sockets::socket class can use.
Definition address_family.hpp:30
@ success
Operation successful.
Definition socket_error.hpp:34
@ port
The xtd::uri::port data.
Definition uri_components.hpp:25
@ other
The operating system is other.
Definition platform_id.hpp:60
@ dgram
Supports datagrams, which are connectionless, unreliable messages of a fixed (typically small) maximu...
Definition socket_type.hpp:38
Contains xtd::iequatable interface.
Contains xtd::net::ip_end_point class.
Contains xtd::threading::manual_reset_event exception.
The xtd::net::sockets namespace provides a managed implementation of the Berkeley Sockets interface f...
Definition address_family.hpp:16
The xtd::net namespace provides a simple programming interface for many of the protocols used on netw...
Definition cookie_exception.hpp:10
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
constexpr const_pointer data() const noexcept
Gets direct access to the underlying contiguous storage.
Definition read_only_span.hpp:201
Contains xtd::object class.
Contains xtd::net::sockets::socket class.
Contains xtd::string alias.