Struct NetworkEndpoint
Representation of an endpoint on the network. Typically, this means an IP address and a port
number, and the API provides means to make working with this kind of endpoint easier.
Analoguous to a sockaddr
structure in traditional BSD sockets.
Implements
Inherited Members
Namespace: Unity.Networking.Transport
Assembly: solution.dll
Syntax
public struct NetworkEndpoint : IEquatable<NetworkEndpoint>
Remarks
While this structure can store an IP address, it can't be used to store domain names. In
general, the Unity Transport package does not handle domain names and it is the user's
responsibility to resolve domain names to IP addresses. This can be done with
System.Net.Dns.GetHostEntryAsync"
for example.
Examples
The code below shows how to obtain endpoint structures for different IP addresses and port
combinations (noted in comments in the IP_ADDRESS:PORT
format):
// 127.0.0.1:7777
NetworkEndpoint.LoopbackIpv4.WithPort(7777);
// 0.0.0.0:0
NetworkEndpoint.AnyIpv4;
// 192.168.0.42:7778
NetworkEndpoint.Parse("192.168.0.42", 7778);
// [fe80::210:5aff:feaa:20a2]:52000
NetworkEndpoint.Parse("fe80::210:5aff:feaa:20a2", 52000, NetworkFamily.Ipv6);
Properties
Name | Description |
---|---|
Address | String representation of the endpoint. Same as To |
Any |
Shortcut for the wildcard IPv4 address (0.0.0.0). |
Any |
Shortcut for the wildcard IPv6 address (::). |
Family | Get or set the family of the endpoint. |
Is |
Whether the endpoint is for a wildcard address. |
Is |
Whether the endpoint is for a loopback address. |
Is |
Whether the endpoint is valid or not (based on the address family). |
Length | Length of the raw address representation. Does not include the size of the port and of the family. Generally, there's no use for this property except for low-level code. |
Loopback |
Shortcut for the loopback/localhost IPv4 address (127.0.0.1). |
Loopback |
Shortcut for the loopback/localhost IPv6 address (::1). |
Port | Get or set the port number of the endpoint. |
Raw |
Get or set the raw value of the endpoint's port number. This is only useful to interface with low-level native libraries. Prefer Port in most circumstances, since that value will always match the endianness of the current platform. |
Methods
Name | Description |
---|---|
Equals(object) | Indicates whether this instance and a specified object are equal. |
Equals(Network |
Indicates whether the current object is equal to another object of the same type. |
Get |
Returns the hash code for this instance. |
Get |
Get the raw representation of the endpoint's address. This is only useful for low-level
code that must interface with native libraries, for example if writing a custom
implementation of INetwork |
Parse(string, ushort, Network |
Parse the provided IP address and port. Prefer this method when parsing IP addresses and ports that are known to be good (e.g. hardcoded values). |
Set |
Set the raw representation of the endpoint's address and set its family. This is only
useful for low-level code that must interface with native libraries, for example if
writing a custom implementation of INetwork |
To |
Get a fixed string representation of the endpoint. Useful for contexts where managed types (like string) can't be used (e.g. Burst-compiled code). |
To |
Returns the fully qualified type name of this instance. |
Try |
|
With |
Get a copy of the endpoint that uses the specified port. |