xtd 0.2.0
Loading...
Searching...
No Matches
udp_client.h
Go to the documentation of this file.
1
4#pragma once
5#include "socket.h"
6#include "../ip_end_point.h"
7#include "../../threading/manual_reset_event.h"
8#include "../../iequatable.h"
9#include "../../object.h"
10#include "../../string.h"
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(std::any async_state) : async_state_(async_state) {}
49 std::any 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 std::any 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(std::any async_state) : async_result_socket(async_state) {}
64 std::vector<xtd::byte> buffer_;
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(std::any async_state) : async_result_socket(async_state) {}
71 size_t number_of_bytes_sent_ = 0;
72 };
73
74 struct data;
75
76 public:
78
92 explicit udp_client(uint16 port);
99 explicit udp_client(const xtd::net::ip_end_point& local_end_point);
125 udp_client(const xtd::string& hostname, uint16 port);
127
129 udp_client(udp_client&&) = default;
130 udp_client(const udp_client&) = default;
131 ~udp_client();
132 udp_client& operator =(const udp_client&) = default;
134
136
145 size_t available() const;
146
155 udp_client& client(const xtd::net::sockets::socket& value) noexcept;
156
163 bool dont_fragment() const;
171 udp_client& dont_fragment(bool value);
172
179 bool enable_broadcast() const;
187 udp_client& enable_broadcast(bool value);
188
196 bool exclusive_address_use() const;
205 udp_client& exclusive_address_use(bool value);
206
213 bool multicast_loopback() const;
221 udp_client& multicast_loopback(bool value);
222
229 xtd::byte ttl() const;
237 udp_client& ttl(xtd::byte value);
239
241
251 void allow_nat_traversal(bool allowed);
252
259 xtd::sptr<xtd::iasync_result> begin_receive(xtd::async_callback callback, const std::any& state);
260
271 xtd::sptr<xtd::iasync_result> begin_send(const std::vector<xtd::byte>& dgram, size_t bytes, const xtd::string& hostname, uint16 port, xtd::async_callback callback, const std::any& state);
272
282 xtd::sptr<xtd::iasync_result> begin_send(const std::vector<xtd::byte>& dgram, size_t bytes, const xtd::net::ip_end_point& end_point, xtd::async_callback callback, const std::any& state);
291 xtd::sptr<xtd::iasync_result> begin_send(const std::vector<xtd::byte>& dgram, size_t bytes, xtd::async_callback callback, const std::any& state);
292
297 void close();
298
309 void connect(const xtd::net::ip_end_point& end_point);
321 void connect(const xtd::net::ip_address& ip_address, uint16 port);
333 void connect(const xtd::string& hostname, uint16 port);
334
341 void drop_multicast_group(const xtd::net::ip_address& multicast_address);
349 void drop_multicast_group(const xtd::net::ip_address& multicast_address, uint32 if_index);
350
361 std::vector<xtd::byte> end_receive(xtd::sptr<xtd::iasync_result> async_result, xtd::net::ip_end_point& remote_end_point);
362
372 size_t end_send(xtd::sptr<xtd::iasync_result> async_result);
373
374 using object::equals;
375 bool equals(const udp_client& s) const noexcept override;
376
389 void join_multicast_group(const xtd::net::ip_address& multicast_address);
402 void join_multicast_group(uint32 if_index, const xtd::net::ip_address& multicast_address);
415 void join_multicast_group(const xtd::net::ip_address& multicast_address, xtd::byte ttl);
425 void join_multicast_group(const xtd::net::ip_address& multicast_address, const xtd::net::ip_address& local_address);
426
437 std::vector<xtd::byte> receive(xtd::net::ip_end_point& remote_end_point);
438
451 size_t send(const std::vector<xtd::byte>& dgram, size_t bytes, const xtd::string& hostname, uint16 port);
463 size_t send(const std::vector<xtd::byte>& dgram, size_t bytes, const xtd::net::ip_end_point& end_point);
473 size_t send(const std::vector<xtd::byte>& dgram, size_t bytes);
475
476 protected:
478
483 bool active() const noexcept;
488 udp_client& active(bool value) noexcept;
490
491 private:
492 udp_client(const xtd::net::sockets::socket& socket);
493
494 xtd::sptr<data> data_;
495 };
496 }
497 }
498}
Represents text as a sequence of character units.
Definition basic_string.h:79
Represents the status of an asynchronous operation.
Definition iasync_result.h:25
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.h:22
Identifies a network address. This is an abstract class.
Definition end_point.h:27
Provides an Internet Protocol (IP) address.
Definition ip_address.h:37
Represents a network endpoint as an IP address and a port number.
Definition ip_end_point.h:23
Implements the Berkeley sockets interface.
Definition socket.h:74
Provides User Datagram Protocol (UDP) network services.
Definition udp_client.h:45
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 ...
udp_client(uint16 port)
Initializes a new instance of the xtd::net::sockets::udp_client class and binds it to the local port ...
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...
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...
xtd::net::sockets::socket client() const noexcept
Gets the underlying network xtd::net::sockets::socket.
udp_client()
Initializes a new instance of the xtd::net::sockets::udp_client class.
size_t available() const
Gets the amount of data received from the network that is available to read.
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.h:42
Represents a thread synchronization event that, when signaled, must be reset manually....
Definition manual_reset_event.h:35
Encapsulates operating system specific objects that wait for exclusive access to shared resources.
Definition wait_handle.h:52
#define core_export_
Define shared library export.
Definition core_export.h:13
uint32_t uint32
Represents a 32-bit unsigned integer.
Definition uint32.h:23
std::shared_ptr< type_t > sptr
The xtd::sptr object is a shared pointer.
Definition sptr.h:25
uint16_t uint16
Represents a 16-bit unsigned integer.
Definition uint16.h:23
socket_error
Defines error codes for the xtd::net::sockets::socket class.
Definition socket_error.h:30
xtd::sptr< xtd::iasync_result > async_result
Represents the status of an asynchronous operation.
Definition async_result.h:19
delegate< void(async_result ar)> async_callback
References a method to be called when a corresponding asynchronous operation completes.
Definition delegate.h:36
address_family
Specifies the addressing scheme that an instance of the xtd::net::sockets::socket class can use.
Definition address_family.h:30
@ success
Operation successful.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
Contains xtd::net::sockets::socket class.