Interface INetworkDriver | Unity Transport | 0.2.4-preview.0
docs.unity3d.com
    Show / Hide Table of Contents

    Interface INetworkDriver

    The NetworkDriver interface is the main entry point for the transport. The Driver is similar to a UDP socket which can handle many connections.

    Namespace: Unity.Networking.Transport
    Syntax
    public interface INetworkDriver : IDisposable

    Properties

    IsCreated

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

    Listening

    Declaration
    bool Listening { get; }
    Property Value
    Type Description
    Boolean

    Methods

    Accept()

    Accept a pending connection attempt and get the established connection. This should be called until it returns an invalid connection to make sure all connections are accepted.

    Declaration
    NetworkConnection Accept()
    Returns
    Type Description
    NetworkConnection

    Returns a newly created NetworkConnection if it was Successful and a default(NetworkConnection) if there where no more new NetworkConnections to accept.

    Bind(NetworkEndPoint)

    Bind the NetworkDriver to a port locally. This must be called before the socket can listen for incoming connections.

    Declaration
    int Bind(NetworkEndPoint endpoint)
    Parameters
    Type Name Description
    NetworkEndPoint endpoint

    A valid NetworkEndPoint, can be implicitly cast using an System.Net.IPEndPoint

    Returns
    Type Description
    Int32

    Returns 0 on Success.

    Connect(NetworkEndPoint)

    Establish a new connection to a server with a specific address and port.

    Declaration
    NetworkConnection Connect(NetworkEndPoint endpoint)
    Parameters
    Type Name Description
    NetworkEndPoint endpoint

    A valid NetworkEndPoint, can be implicitly cast using an System.Net.IPEndPoint

    Returns
    Type Description
    NetworkConnection

    CreatePipeline(Type[])

    Create a pipeline which can be used to process data packets sent and received by the transport package. The pipelines must be created in the same order on the client and server since they are identified by an index which is assigned on creation. All pipelines must be created before the first connection is established.

    Declaration
    NetworkPipeline CreatePipeline(params Type[] stages)
    Parameters
    Type Name Description
    Type[] stages
    Returns
    Type Description
    NetworkPipeline

    Disconnect(NetworkConnection)

    Disconnect an existing connection.

    Declaration
    int Disconnect(NetworkConnection con)
    Parameters
    Type Name Description
    NetworkConnection con
    Returns
    Type Description
    Int32

    Returns 0 on Success.

    GetConnectionState(NetworkConnection)

    Get the state of an existing connection. If called with an invalid connection the call will return the Destroyed state.

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

    Listen()

    Enable listening for incoming connections on this driver. Before calling this all connection attempts will be rejected.

    Declaration
    int Listen()
    Returns
    Type Description
    Int32

    Returns 0 on Success.

    LocalEndPoint()

    Declaration
    NetworkEndPoint LocalEndPoint()
    Returns
    Type Description
    NetworkEndPoint

    PopEvent(out NetworkConnection, out DataStreamReader)

    Receive an event for any connection.

    Declaration
    NetworkEvent.Type PopEvent(out NetworkConnection con, out DataStreamReader bs)
    Parameters
    Type Name Description
    NetworkConnection con
    DataStreamReader bs
    Returns
    Type Description
    NetworkEvent.Type

    PopEventForConnection(NetworkConnection, out DataStreamReader)

    Receive an event for a specific connection. Should be called until it returns Empty, even if the socket is disconnected.

    Declaration
    NetworkEvent.Type PopEventForConnection(NetworkConnection con, out DataStreamReader bs)
    Parameters
    Type Name Description
    NetworkConnection con
    DataStreamReader bs
    Returns
    Type Description
    NetworkEvent.Type

    RemoteEndPoint(NetworkConnection)

    Declaration
    NetworkEndPoint RemoteEndPoint(NetworkConnection con)
    Parameters
    Type Name Description
    NetworkConnection con
    Returns
    Type Description
    NetworkEndPoint

    ScheduleUpdate(JobHandle)

    Schedule a job to update the state of the NetworkDriver, read messages and events from the underlying network interface and populate the event queues to allow reading from connections concurrently.

    Declaration
    JobHandle ScheduleUpdate(JobHandle dep = null)
    Parameters
    Type Name Description
    JobHandle dep

    Used to chain dependencies for jobs.

    Returns
    Type Description
    JobHandle

    A for the ScheduleUpdate Job.

    Send(NetworkPipeline, NetworkConnection, IntPtr, Int32)

    Send a message to the specific connection.

    Declaration
    int Send(NetworkPipeline pipe, NetworkConnection con, IntPtr data, int len)
    Parameters
    Type Name Description
    NetworkPipeline pipe
    NetworkConnection con
    IntPtr data
    Int32 len
    Returns
    Type Description
    Int32

    Send(NetworkPipeline, NetworkConnection, DataStreamWriter)

    Send a message to the specific connection.

    Declaration
    int Send(NetworkPipeline pipe, NetworkConnection con, DataStreamWriter strm)
    Parameters
    Type Name Description
    NetworkPipeline pipe
    NetworkConnection con

    A NetworkConnection to the endpoint you want to send to.

    DataStreamWriter strm

    A valid DataStreamWriter.

    Returns
    Type Description
    Int32

    Returns the size in bytes that was sent, -1 on failure.

    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