docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Struct NetworkDriver.Concurrent

    Structure that can be used to access a NetworkDriver from multiple jobs. Only a subset of operations are supported because not all operations are safe to perform concurrently. Must be obtained with the ToConcurrent() method.

    Inherited Members
    ValueType.Equals(object)
    ValueType.GetHashCode()
    ValueType.ToString()
    object.Equals(object, object)
    object.GetType()
    object.ReferenceEquals(object, object)
    Namespace: Unity.Networking.Transport
    Assembly: Unity.Networking.Transport.dll
    Syntax
    public struct NetworkDriver.Concurrent

    Methods

    AbortSend(DataStreamWriter)

    Aborts a send started with BeginSend(NetworkPipeline, NetworkConnection, out DataStreamWriter, int).

    Declaration
    public void AbortSend(DataStreamWriter writer)
    Parameters
    Type Name Description
    DataStreamWriter writer

    DataStreamWriter to cancel.

    BeginSend(NetworkConnection, out DataStreamWriter, int)

    Begin sending data on the given connection (default pipeline).

    Declaration
    public int BeginSend(NetworkConnection connection, out DataStreamWriter writer, int requiredPayloadSize = 0)
    Parameters
    Type Name Description
    NetworkConnection connection

    Connection to send the data to.

    DataStreamWriter writer

    DataStreamWriter the data can be written to.

    int requiredPayloadSize

    Size that the returned DataStreamWriter must support. The method will return an error if that payload size is not supported by the pipeline. Defaults to 0, which means the DataStreamWriter will be as large as it can be.

    Returns
    Type Description
    int

    0 on success, a negative value on error.

    BeginSend(NetworkPipeline, NetworkConnection, out DataStreamWriter, int)

    Begin sending data on the given connection and pipeline.

    Declaration
    public int BeginSend(NetworkPipeline pipe, NetworkConnection connection, out DataStreamWriter writer, int requiredPayloadSize = 0)
    Parameters
    Type Name Description
    NetworkPipeline pipe

    Pipeline to send the data on.

    NetworkConnection connection

    Connection to send the data to.

    DataStreamWriter writer

    DataStreamWriter the data can be written to.

    int requiredPayloadSize

    Size that the returned DataStreamWriter must support. The method will return an error if that payload size is not supported by the pipeline. Defaults to 0, which means the DataStreamWriter will be as large as it can be.

    Returns
    Type Description
    int

    0 on success, a negative error code on error.

    EndSend(DataStreamWriter)

    Enqueue a send operation for the data in the given DataStreamWriter, which must have been obtained by a prior call to BeginSend(NetworkPipeline, NetworkConnection, out DataStreamWriter, int).

    Declaration
    public int EndSend(DataStreamWriter writer)
    Parameters
    Type Name Description
    DataStreamWriter writer

    DataStreamWriter to send.

    Returns
    Type Description
    int

    The number of bytes to be sent on success, a negative value on error.

    Remarks

    This method doesn't actually send anything on the wire. It simply enqueues the send operation, which will be performed in the next ScheduleFlushSend(JobHandle) or ScheduleUpdate(JobHandle) job.

    GetConnectionState(NetworkConnection)

    Get the current state of the given connection.

    Declaration
    public NetworkConnection.State GetConnectionState(NetworkConnection id)
    Parameters
    Type Name Description
    NetworkConnection id
    Returns
    Type Description
    NetworkConnection.State

    State of the connection.

    GetMaxSupportedMessageSize(NetworkConnection)

    Retrieves the max supported message size (calculated Path MTU) for a given connection. If discovery has not been completed yet, this will return -1.

    Declaration
    public int GetMaxSupportedMessageSize(NetworkConnection connection)
    Parameters
    Type Name Description
    NetworkConnection connection

    The connection to check

    Returns
    Type Description
    int

    The calculated Path MTU size for the connection (clamped to a range of 1024..maxMessageSize)

    Remarks

    Path MTU discovery is done once as part of the connection handshake. Once the system has done the initial Path MTU discovery, it will not update this value if the Path MTU changes. In the event the path MTU changes to be smaller, it will require a disconnect and reconnect to update the value (which is often better in game contexts than adjusting to a dynamically changing value)

    MaxHeaderSize(NetworkPipeline)

    Get the maximum size of headers when sending on the given pipeline.

    Declaration
    public int MaxHeaderSize(NetworkPipeline pipe)
    Parameters
    Type Name Description
    NetworkPipeline pipe

    Pipeline to get the header size for.

    Returns
    Type Description
    int

    The maximum size of the headers on the given pipeline.

    Remarks

    Only accounts for the Unity Transport headers (no UDP or IP).

    PopEventForConnection(NetworkConnection, out DataStreamReader)

    Pops the next event from the event queue for the given connection, Empty will be returned if there are no more events.

    Declaration
    public NetworkEvent.Type PopEventForConnection(NetworkConnection connection, out DataStreamReader reader)
    Parameters
    Type Name Description
    NetworkConnection connection

    Connection for which to pop the event.

    DataStreamReader reader

    DataStreamReader from which the event data (e.g. payload) can be read from.

    Returns
    Type Description
    NetworkEvent.Type

    The type of the event popped.

    Remarks

    The reader obtained from this method will contain different things for different event types. For Data, it contains the actual received payload. For Disconnect, it contains a single byte identifying the reason for the disconnection (see DisconnectReason). For other event types, it contains nothing.

    PopEventForConnection(NetworkConnection, out DataStreamReader, out NetworkPipeline)

    Pops the next event from the event queue for the given connection, Empty will be returned if there are no more events.

    Declaration
    public NetworkEvent.Type PopEventForConnection(NetworkConnection connection, out DataStreamReader reader, out NetworkPipeline pipe)
    Parameters
    Type Name Description
    NetworkConnection connection

    Connection for which to pop the event.

    DataStreamReader reader

    DataStreamReader from which the event data (e.g. payload) can be read from.

    NetworkPipeline pipe

    Pipeline on which the data event was received.

    Returns
    Type Description
    NetworkEvent.Type

    The type of the event popped.

    Remarks

    The reader obtained from this method will contain different things for different event types. For Data, it contains the actual received payload. For Disconnect, it contains a single byte identifying the reason for the disconnection (see DisconnectReason). For other event types, it contains nothing.

    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)