#include <Pt/Net/Endpoint.h>
Host and service address. More...
Public Member Functions | |
| Endpoint () | |
| Creates an empty endpoint. | |
| Endpoint (const std::string &host, unsigned short port) | |
| Creates an endpoint for host and port. | |
| Endpoint (const char *host, unsigned short port) | |
| Creates an endpoint for host and port. | |
| Endpoint (const Endpoint &src) | |
| Copies the endpoint. | |
| ~Endpoint () | |
| Destroys the endpoint. | |
| Endpoint & | operator= (const Endpoint &src) |
| Assigns the endpoint. | |
| void | clear () |
| Clears the endpoint. | |
| std::string | toString () const |
| Returns the endpoint as a string. | |
Static Public Member Functions | |
| static Endpoint | ip4Any (unsigned short port) |
| Creates the IPv4 any-address for port. | |
| static Endpoint | ip4Loopback (unsigned short port) |
| Creates the IPv4 loopback address for port. | |
| static Endpoint | ip4Broadcast (unsigned short port) |
| Creates the IPv4 broadcast address for port. | |
| static Endpoint | ip6Any (unsigned short port) |
| Creates the IPv6 any-address for port. | |
| static Endpoint | ip6Loopback (unsigned short port) |
| Creates the IPv6 loopback address for port. | |
Endpoint is the copyable address value that TCP and UDP operations use: it names a host and a service port, but it does not open a socket, and constructing one does not start a connection or a listen.
A host string and a port number construct it, and the host may be a DNS name or a numeric IPv4 or IPv6 address. Name resolution happens when a socket uses the endpoint, not when the value is created, so an invalid name fails on listen, bind, or connect rather than on construction.
Factory functions build the IPv4 and IPv6 any and loopback addresses, and the IPv4 broadcast address, for a port, and those addresses do not perform name resolution. The any-address is the local wildcard used to listen or bind on every local interface, loopback is the host itself, and the IPv4 broadcast address is the send destination for UDP broadcast.
toString() formats the endpoint for display, clear() resets it to an empty address, and copy and assignment duplicate the address, not a socket.
The example constructs a named host-and-port endpoint and an IPv4 any-address for a port, so the first is a remote or named host and the second is a local wildcard.