docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Struct NetworkStreamDriver

    Singleton that can hold a reference to the NetworkDriverStore and that should be used to easily listening for new connection or connecting to server. Provide also other shortcut for retrieving the remote address of a NetworkStreamConnection or its underlying transport state.

    Implements
    IComponentData
    IQueryTypeParameter
    Inherited Members
    ValueType.Equals(object)
    ValueType.GetHashCode()
    object.Equals(object, object)
    object.GetType()
    object.ReferenceEquals(object, object)
    Namespace: Unity.NetCode
    Assembly: Unity.NetCode.dll
    Syntax
    public struct NetworkStreamDriver : IComponentData, IQueryTypeParameter

    Properties

    ConnectionEventsForTick

    Stores all NetCodeConnectionEvent's raised by Netcode for this SimulationSystemGroup tick. Allows user-code to subscribe to connection and disconnection events. Self-cleaning list, thus no consume API.

    Declaration
    public readonly NativeArray<NetCodeConnectionEvent>.ReadOnly ConnectionEventsForTick { get; }
    Property Value
    Type Description
    NativeArray<NetCodeConnectionEvent>.ReadOnly
    Remarks

    Because events are only valid for a single tick, any code that reads from (i.e. consumes) these events must update in the SimulationSystemGroup.

    Methods

    Connect(EntityManager, NetworkEndpoint, Entity)

    Initiate a connection to the remote endpoint address.

    Declaration
    public Entity Connect(EntityManager entityManager, NetworkEndpoint endpoint, Entity ent = default)
    Parameters
    Type Name Description
    EntityManager entityManager

    The entity manager to use to create the new entity, if ent equals Null

    NetworkEndpoint endpoint

    The remote address we want to connect

    Entity ent

    An optional entity to use to create the connection. If not set, a new entity will be create instead

    Returns
    Type Description
    Entity

    The entity that hold the NetworkStreamConnection. If the endpoint is not valid

    Exceptions
    Type Condition
    InvalidOperationException

    Throw an exception if the driver is not created or if multiple drivers are register

    GetConnectionState(NetworkStreamConnection)

    The current state of the internal transport connection.

    Declaration
    public NetworkConnection.State GetConnectionState(NetworkStreamConnection connection)
    Parameters
    Type Name Description
    NetworkStreamConnection connection
    Returns
    Type Description
    NetworkConnection.State
    Remarks

    Is different from the ConnectionState.State and it is less granular.

    GetLocalEndPoint()

    Get the local endpoint (the endpoint remote peers will use to reach this driver) used by the first driver inside NetworkDriverStore. This is similar to calling GetLocalEndPoint(int) with NetworkDriverStore.FirstDriverId as argument.

    Declaration
    public NetworkEndpoint GetLocalEndPoint()
    Returns
    Type Description
    NetworkEndpoint

    The local endpoint of the first driver.

    GetLocalEndPoint(int)

    Get the local endpoint used by the driver (the endpoint remote peers will use to reach this driver).
    When multiple drivers exist, e.g. when using both IPC and Socket connection, multiple drivers will be available in the NetworkDriverStore.

    Declaration
    public NetworkEndpoint GetLocalEndPoint(int driverId)
    Parameters
    Type Name Description
    int driverId

    Id of the driver. See GetNetworkDriver(int)

    Returns
    Type Description
    NetworkEndpoint

    The local endpoint of the driver.

    GetRemoteEndPoint(NetworkStreamConnection)

    The remote connection address. This is the seen public ip address of the connection.

    Declaration
    public NetworkEndpoint GetRemoteEndPoint(NetworkStreamConnection connection)
    Parameters
    Type Name Description
    NetworkStreamConnection connection
    Returns
    Type Description
    NetworkEndpoint

    When relay is used, the current relay host address. Otherwise the remote endpoint address.

    Remarks

    Be aware that this method work sliglty differnetly than the NetworkDriver.GetRemoteEndpoint. The Unity.Networking.Transport.NetworkDriver.GetRemoteEndpoint(Unity.Networking.Transport.NetworkConnection) does not always return a valid address when used with relay (once the connection is established it become the RelayAllocationId). We instead wanted a consistent behaviour for this method: always return the address to which this connection is is connected/connecting to.

    Listen(NetworkEndpoint)

    Tell all the registered NetworkDriverStore drivers to start listening for incoming connections.

    Declaration
    public bool Listen(NetworkEndpoint endpoint)
    Parameters
    Type Name Description
    NetworkEndpoint endpoint

    The local address to use. This is the address that will be used to bind the underlying socket.

    Returns
    Type Description
    bool

    UseRelay(NetworkStreamConnection)

    Check if the given connection is using relay to connect to the remote endpoint

    Declaration
    public bool UseRelay(NetworkStreamConnection connection)
    Parameters
    Type Name Description
    NetworkStreamConnection connection
    Returns
    Type Description
    bool

    Either if the connection is using the relay or not.

    Implements

    IComponentData
    IQueryTypeParameter
    In This Article
    Back to top
    Copyright © 2025 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)