docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    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
    IEquatable<NetworkEndpoint>
    Inherited Members
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetType()
    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 ToString().

    AnyIpv4

    Shortcut for the wildcard IPv4 address (0.0.0.0).

    AnyIpv6

    Shortcut for the wildcard IPv6 address (::).

    Family

    Get or set the family of the endpoint.

    IsAny

    Whether the endpoint is for a wildcard address.

    IsLoopback

    Whether the endpoint is for a loopback address.

    IsValid

    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.

    LoopbackIpv4

    Shortcut for the loopback/localhost IPv4 address (127.0.0.1).

    LoopbackIpv6

    Shortcut for the loopback/localhost IPv6 address (::1).

    Port

    Get or set the port number of the endpoint.

    RawPort

    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(NetworkEndpoint)

    Indicates whether the current object is equal to another object of the same type.

    GetHashCode()

    Returns the hash code for this instance.

    GetRawAddressBytes()

    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 INetworkInterface.

    Parse(string, ushort, NetworkFamily)

    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).

    SetRawAddressBytes(NativeArray<byte>, NetworkFamily)

    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 INetworkInterface.

    ToFixedString()

    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).

    ToString()

    Returns the fully qualified type name of this instance.

    TryParse(string, ushort, out NetworkEndpoint, NetworkFamily)
    WithPort(ushort)

    Get a copy of the endpoint that uses the specified port.

    Operators

    Name Description
    operator ==(NetworkEndpoint, NetworkEndpoint)
    operator !=(NetworkEndpoint, NetworkEndpoint)
    In This Article
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023