Provides User Datagram Protocol (UDP) network services.
Provides User Datagram Protocol (UDP) network services.
Definition udp_client.h:45
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.h:42
- Inheritance
- xtd::object → xtd::net::sockets::udp_client
- Header
#include <xtd/net/sockets/udp_client>
- Namespace
- xtd::net::sockets
- Library
- xtd.core
- Note
- Do not call xtd::net::sockets::udp_client::send using a host name or xtd::net::ip_end_point if you have already specified a default remote host. If you do, xtd::net::sockets::udp_client will throw an exception.
- Examples
- The following example shows how to use IPv4 xtd::net::sockets::udp_client class.
#include <xtd/collections/generic/list>
#include <xtd/io/stream_reader>
#include <xtd/net/sockets/udp_client>
#include <xtd/net/ip_end_point>
#include <xtd/threading/thread>
#include <xtd/console>
auto main() -> int {
auto terminate_app = false;
while (!terminate_app) {
auto buffer =
udp.receive(incoming_end_point);
if (buffer.size() && buffer[0] != 0xFF)
}
}};
auto counter = 0;
while (!terminate_app) {
thread::sleep(50_ms);
}
}};
server.start();
terminate_app = true;
server.join();
}
virtual size_type size() const noexcept
Returns the number of elements in the container, i.e. std::distance(xtd::collections::generic::list::...
Definition list.h:368
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
Definition list.h:71
static console_key_info read_key()
Obtains the next character or function key pressed by the user. The pressed key is displayed in the c...
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
static const ip_address any
Provides an IP address that indicates that the server must listen for client activity on all network ...
Definition ip_address.h:44
static const ip_address loopback
Provides the IP loopback address. This field is constant.
Definition ip_address.h:60
Represents a network endpoint as an IP address and a port number.
Definition ip_end_point.h:23
xtd::net::sockets::socket client() const noexcept
Gets the underlying network xtd::net::sockets::socket.
Creates and controls a thread, sets its priority, and gets its status.
Definition thread.h:43
@ udp
User Datagram Protocol.
The xtd::collections::generic namespace contains interfaces and classes that define generic collectio...
Definition dictionary.h:15
The xtd::net::sockets namespace provides a managed implementation of the Berkeley Sockets interface f...
Definition address_family.h:16
The xtd::net namespace provides a simple programming interface for many of the protocols used on netw...
Definition cookie_exception.h:10
The xtd::threading namespace provides classes and interfaces that enable multithreaded programming....
Definition abandoned_mutex_exception.h:10
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
- Examples
- The following example shows how to use IPv6 xtd::net::sockets::udp_client class.
#include <xtd/collections/generic/list>
#include <xtd/io/stream_reader>
#include <xtd/net/sockets/udp_client>
#include <xtd/net/ip_end_point>
#include <xtd/threading/thread>
#include <xtd/console>
auto main() -> int {
auto terminate_app = false;
while (!terminate_app) {
auto buffer =
udp.receive(incoming_end_point);
if (buffer.size() && buffer[0] != 0xFF)
}
}};
auto counter = 0;
while (!terminate_app) {
thread::sleep(50_ms);
}
}};
server.start();
terminate_app = true;
server.join();
}
static const ip_address ip_v6_loopback
Provides the IP loopback address. This field is constant.
Definition ip_address.h:53
static const ip_address ip_v6_any
The Socket::Bind method uses the cIPv6Any field to indicate that a Socket must listen for client acti...
Definition ip_address.h:50
@ inter_network_v6
Address for IP version 6.
- Examples
- udp_client_ip_v4.cpp, and udp_client_ip_v6.cpp.
|
void | allow_nat_traversal (bool allowed) |
| Enables or disables Network Address Translation (NAT) traversal on a xtd::net::sockets::udp_client instance.
|
|
xtd::sptr< xtd::iasync_result > | begin_receive (xtd::async_callback callback, const std::any &state) |
| xtd::net::sockets::udp_client::receives a datagram from a remote host asynchronously.
|
|
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) |
| xtd::net::sockets::udp_client::sends a datagram to a destination asynchronously. The destination is specified by the host name and port number.
|
|
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) |
| xtd::net::sockets::udp_client::sends a datagram to a destination asynchronously. The destination is specified by a EndPoint.
|
|
xtd::sptr< xtd::iasync_result > | begin_send (const std::vector< xtd::byte > &dgram, size_t bytes, xtd::async_callback callback, const std::any &state) |
| xtd::net::sockets::udp_client::sends a datagram to a remote host asynchronously. The destination was specified previously by a call to xtd::net::sockets::udp_client::connect.
|
|
void | close () |
| Closes the UDP connection.
|
|
void | connect (const xtd::net::ip_end_point &end_point) |
| Establishes a default remote host using the specified network endpoint.
|
|
void | connect (const xtd::net::ip_address &ip_address, uint16 port) |
| Establishes a default remote host using the specified IP address and port number.
|
|
void | connect (const xtd::string &hostname, uint16 port) |
| Establishes a default remote host using the specified hostname and port number.
|
|
void | drop_multicast_group (const xtd::net::ip_address &multicast_address) |
| Leaves a multicast group.
|
|
void | drop_multicast_group (const xtd::net::ip_address &multicast_address, uint32 if_index) |
| Leaves a multicast group.
|
|
std::vector< xtd::byte > | end_receive (xtd::sptr< xtd::iasync_result > async_result, xtd::net::ip_end_point &remote_end_point) |
| Ends a pending asynchronous receive.
|
|
size_t | end_send (xtd::sptr< xtd::iasync_result > async_result) |
| Ends a pending asynchronous send.
|
|
bool | equals (const udp_client &s) const noexcept override |
|
void | join_multicast_group (const xtd::net::ip_address &multicast_address) |
| Adds a xtd::net::sockets::udp_client to a multicast group.
|
|
void | join_multicast_group (uint32 if_index, const xtd::net::ip_address &multicast_address) |
| Adds a xtd::net::sockets::udp_client to a multicast group.
|
|
void | join_multicast_group (const xtd::net::ip_address &multicast_address, xtd::byte ttl) |
| Adds a xtd::net::sockets::udp_client to a multicast group with the specified Time to Live (TTL).
|
|
void | join_multicast_group (const xtd::net::ip_address &multicast_address, const xtd::net::ip_address &local_address) |
| Adds a xtd::net::sockets::udp_client to a multicast group.
|
|
std::vector< xtd::byte > | receive (xtd::net::ip_end_point &remote_end_point) |
| Returns a UDP datagram that was sent by a remote host.
|
|
size_t | send (const std::vector< xtd::byte > &dgram, size_t bytes, const xtd::string &hostname, uint16 port) |
| xtd::net::sockets::udp_client::sends a UDP datagram to a specified port on a specified remote host.
|
|
size_t | send (const std::vector< xtd::byte > &dgram, size_t bytes, const xtd::net::ip_end_point &end_point) |
| xtd::net::sockets::udp_client::sends a UDP datagram to the host at the specified remote endpoint.
|
|
size_t | send (const std::vector< xtd::byte > &dgram, size_t bytes) |
| xtd::net::sockets::udp_client::sends a UDP datagram to a remote host.
|
|
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.
|
|
|
| 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.
|
|
virtual bool | equals (const udp_client &) const noexcept=0 |
| Indicates wheth er the current object is equal to another object of the same type.
|
|
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.
|
|