docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Struct NetworkConnection

    Public representation of a connection. This is obtained by calling Accept(out NativeArray<byte>) (on servers) or Connect(NetworkEndpoint, NativeArray<byte>) (on clients) and acts as a handle to the communication session with a remote peer.

    Implements
    IEquatable<NetworkConnection>
    Inherited Members
    object.Equals(object, object)
    object.GetType()
    object.ReferenceEquals(object, object)
    Namespace: Unity.Networking.Transport
    Assembly: Unity.Networking.Transport.dll
    Syntax
    public struct NetworkConnection : IEquatable<NetworkConnection>

    Properties

    IsCreated

    Whether the connection was correctly obtained from a call to Accept(out NativeArray<byte>) or Connect(NetworkEndpoint, NativeArray<byte>).

    Declaration
    public bool IsCreated { get; }
    Property Value
    Type Description
    bool

    True if created correctly, false otherwise.

    Methods

    Close(NetworkDriver)

    Close an active connection. Strictly identical to Disconnect(NetworkDriver).

    Declaration
    public int Close(NetworkDriver driver)
    Parameters
    Type Name Description
    NetworkDriver driver

    Driver on which to perform the operation.

    Returns
    Type Description
    int

    0 on success, a negative error code otherwise.

    Disconnect(NetworkDriver)

    Close an active connection. Strictly identical to Close(NetworkDriver).

    Declaration
    public int Disconnect(NetworkDriver driver)
    Parameters
    Type Name Description
    NetworkDriver driver

    Driver on which to perform the operation.

    Returns
    Type Description
    int

    0 on success, a negative error code otherwise.

    Equals(object)

    Declaration
    public override bool Equals(object o)
    Parameters
    Type Name Description
    object o
    Returns
    Type Description
    bool
    Overrides
    ValueType.Equals(object)

    Equals(NetworkConnection)

    Declaration
    public bool Equals(NetworkConnection o)
    Parameters
    Type Name Description
    NetworkConnection o
    Returns
    Type Description
    bool

    GetHashCode()

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    int
    Overrides
    ValueType.GetHashCode()

    GetState(NetworkDriver)

    Get the current state of a connection.

    Declaration
    public NetworkConnection.State GetState(NetworkDriver driver)
    Parameters
    Type Name Description
    NetworkDriver driver

    Driver to get the state from.

    Returns
    Type Description
    NetworkConnection.State

    Current state of the connection.

    PopEvent(NetworkDriver, out DataStreamReader)

    Pop the next available event on the connection.

    Declaration
    public NetworkEvent.Type PopEvent(NetworkDriver driver, out DataStreamReader stream)
    Parameters
    Type Name Description
    NetworkDriver driver

    Driver from which to get the event.

    DataStreamReader stream

    Reader into the data associated to the event. Only populated if the returned event is Data or Disconnect, where respectively the data will be either the received payload, or the disconnection reason (as a single byte).

    Returns
    Type Description
    NetworkEvent.Type

    Type of the popped event. Empty if nothing to pop.

    PopEvent(NetworkDriver, out DataStreamReader, out NetworkPipeline)

    Pop the next available event on the connection.

    Declaration
    public NetworkEvent.Type PopEvent(NetworkDriver driver, out DataStreamReader stream, out NetworkPipeline pipeline)
    Parameters
    Type Name Description
    NetworkDriver driver

    Driver from which to get the event.

    DataStreamReader stream

    Reader into the data associated to the event. Only populated if the returned event is Data or Disconnect, where respectively the data will be either the received payload, or the disconnection reason (as a single byte).

    NetworkPipeline pipeline

    Pipeline on which the data was received.

    Returns
    Type Description
    NetworkEvent.Type

    Type of the popped event. Empty if nothing to pop.

    ToFixedString()

    Return a fixed string representation of the connection. For use in contexts where ToString() can't be used (e.g. Burst-compiled code).

    Declaration
    public FixedString128Bytes ToFixedString()
    Returns
    Type Description
    FixedString128Bytes

    Fixed string representation of the connection.

    ToString()

    Declaration
    public override string ToString()
    Returns
    Type Description
    string
    Overrides
    ValueType.ToString()

    Operators

    operator ==(NetworkConnection, NetworkConnection)

    Declaration
    public static bool operator ==(NetworkConnection lhs, NetworkConnection rhs)
    Parameters
    Type Name Description
    NetworkConnection lhs
    NetworkConnection rhs
    Returns
    Type Description
    bool

    operator !=(NetworkConnection, NetworkConnection)

    Declaration
    public static bool operator !=(NetworkConnection lhs, NetworkConnection rhs)
    Parameters
    Type Name Description
    NetworkConnection lhs
    NetworkConnection rhs
    Returns
    Type Description
    bool

    Implements

    IEquatable<T>
    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)