Skip to main content

Unity.Networking.Transport.NetworkDriver

The NetworkDriver is an implementation of Virtual Connections over any transport.

Basic usage:

var driver = NetworkDriver.Create();
Implements#

System.IDisposable

Inherited Members#

ValueType.Equals(Object)

ValueType.GetHashCode()

ValueType.ToString()

Object.Equals(Object, Object)

Object.GetType()

Object.ReferenceEquals(Object, Object)

Namespace: System.Dynamic.ExpandoObject#
Assembly: transport.dll#
Syntax#
public struct NetworkDriver : IDisposable

NetworkDriver(INetworkInterface, INetworkParameter[])#

Declaration#

public NetworkDriver(INetworkInterface netIf, params INetworkParameter[] param)

Parameters#

TypeNameDescription
INetworkInterfacenetIf
INetworkParameter[]param

#

Bound#

Declaration#

public readonly bool Bound { get; }

Property Value#

TypeDescription
System.Boolean

IsCreated#

Returns if NetworkDriver has been created

Declaration#

public readonly bool IsCreated { get; }

Property Value#

TypeDescription
System.Boolean

LastUpdateTime#

Gets the value of the last update time

Declaration#

public readonly long LastUpdateTime { get; }

Property Value#

TypeDescription
System.Int64

Listening#

Gets or sets if the driver is Listening

Declaration#

public bool Listening { get; }

Property Value#

TypeDescription
System.Boolean

ReceiveErrorCode#

Gets or sets Receive Error Code

Declaration#

public int ReceiveErrorCode { get; }

Property Value#

TypeDescription
System.Int32

#

AbortSend(DataStreamWriter)#

Aborts a asynchronous send.

Declaration#

public void AbortSend(DataStreamWriter writer)

Parameters#

TypeNameDescription
DataStreamWriterwriterIf you require the payload to be of certain size.

Exceptions#

TypeCondition
System.InvalidOperationExceptionIf endsend is called with a matching BeginSend call.
System.InvalidOperationExceptionIf the connection got closed between the call of being and end send.

Accept()#

Checks to see if there are any new connections to Accept.

Declaration#

public NetworkConnection Accept()

Returns#

TypeDescription
NetworkConnectionIf accept fails it returns a default NetworkConnection.

AllocateMemory(ref Int32)#

Allocates temporary memory in NetworkDriver's data stream. You don't need to deallocate it If you need to call this function several times - use PinMemoryTillUpdate(Int32) to move 'head'

Declaration#

public IntPtr AllocateMemory(ref int dataLen)

Parameters#

TypeNameDescription
System.Int32dataLenSize of memory to allocate in bytes. Must be > 0

Returns#

TypeDescription
System.IntPtrPointer to allocated memory or IntPtr.Zero if there is no space left (this function doesn't set ReceiveErrorCode! caller should decide if this is Out of memory or something else)

BeginSend(NetworkConnection, out DataStreamWriter, Int32)#

Acquires a DataStreamWriter for starting a asynchronous send.

Declaration#

public int BeginSend(NetworkConnection id, out DataStreamWriter writer, int requiredPayloadSize = 0)

Parameters#

TypeNameDescription
NetworkConnectionidThe NetworkConnection id to write through
DataStreamWriterwriterA DataStreamWriter to write to
System.Int32requiredPayloadSizeIf you require the payload to be of certain size

Returns#

TypeDescription
System.Int32Returns Success on a successful acquire. Otherwise returns an StatusCode indicating the error.

Remarks#

Will throw a System.InvalidOperationException if the connection is in a Connecting state.

BeginSend(NetworkPipeline, NetworkConnection, out DataStreamWriter, Int32)#

Acquires a DataStreamWriter for starting a asynchronous send.

Declaration#

public int BeginSend(NetworkPipeline pipe, NetworkConnection id, out DataStreamWriter writer, int requiredPayloadSize = 0)

Parameters#

TypeNameDescription
NetworkPipelinepipeThe NetworkPipeline to write through
NetworkConnectionidThe NetworkConnection id to write through
DataStreamWriterwriterA DataStreamWriter to write to
System.Int32requiredPayloadSizeIf you require the payload to be of certain size

Returns#

TypeDescription
System.Int32Returns Success on a successful acquire. Otherwise returns an StatusCode indicating the error.

Remarks#

Will throw a System.InvalidOperationException if the connection is in a Connecting state.

Bind(NetworkEndPoint)#

Bind the driver to a endpoint.

Declaration#

public int Bind(NetworkEndPoint endpoint)

Parameters#

TypeNameDescription
NetworkEndPointendpointThe endpoint to bind to.

Returns#

TypeDescription
System.Int32Returns 0 on success. And a negative value if a error occured.

Exceptions#

TypeCondition
System.InvalidOperationExceptionIf the driver is not created properly
System.InvalidOperationExceptionIf bind is called more then once on the driver
System.InvalidOperationExceptionIf bind is called after a connection has already been established

Connect(NetworkEndPoint)#

Connects the driver to a endpoint

Declaration#

public NetworkConnection Connect(NetworkEndPoint endpoint)

Parameters#

TypeNameDescription
NetworkEndPointendpoint

Returns#

TypeDescription
NetworkConnectionIf connect fails it returns a default NetworkConnection.

Exceptions#

TypeCondition
System.InvalidOperationExceptionIf the driver is not created properly

Create(INetworkParameter[])#

Helper function for creating a NetworkDriver.

Declaration#

public static NetworkDriver Create(params INetworkParameter[] param)

Parameters#

TypeNameDescription
INetworkParameter[]paramAn optional array of INetworkParameter. There are currently only two INetworkParameter, the NetworkDataStreamParameter and the NetworkConfigParameter.

Returns#

TypeDescription
NetworkDriver

Exceptions#

TypeCondition
System.InvalidOperationException

CreatePipeline(Type[])#

Create a new pipeline.

Declaration#

public NetworkPipeline CreatePipeline(params Type[] stages)

Parameters#

TypeNameDescription
System.Type[]stagesAn array of stages the pipeline should contain.

Returns#

TypeDescription
NetworkPipeline

Exceptions#

TypeCondition
System.InvalidOperationExceptionIf the driver is not created properly
System.InvalidOperationExceptionA connection has already been established

Disconnect(NetworkConnection)#

Disconnects a NetworkConnection

Declaration#

public int Disconnect(NetworkConnection id)

Parameters#

TypeNameDescription
NetworkConnectionidThe NetworkConnection we want to Disconnect.

Returns#

TypeDescription
System.Int32Return 0 on success.

Dispose()#

Declaration#

public void Dispose()

EndSend(DataStreamWriter)#

Ends a asynchronous send.

Declaration#

public int EndSend(DataStreamWriter writer)

Parameters#

TypeNameDescription
DataStreamWriterwriterIf you require the payload to be of certain size.

Returns#

TypeDescription
System.Int32The length of the buffer sent if nothing went wrong.

Exceptions#

TypeCondition
System.InvalidOperationExceptionIf endsend is called with a matching BeginSend call.
System.InvalidOperationExceptionIf the connection got closed between the call of being and end send.

GetConnectionState(NetworkConnection)#

Gets the connection state using the specified NetworkConnection

Declaration#

public NetworkConnection.State GetConnectionState(NetworkConnection con)

Parameters#

TypeNameDescription
NetworkConnectionconThe connection

Returns#

TypeDescription
NetworkConnection.StateThe network connection state

GetEventQueueSizeForConnection(NetworkConnection)#

Returns the size of the EventQueue for a specific connection

Declaration#

public int GetEventQueueSizeForConnection(NetworkConnection connectionId)

Parameters#

TypeNameDescription
NetworkConnectionconnectionIdConnection for which to get the event queue size.

Returns#

TypeDescription
System.Int32If the connection is valid it returns the size of the event queue otherwise it returns 0.

GetPipelineBuffers(NetworkPipeline, NetworkPipelineStageId, NetworkConnection, out NativeArray\<Byte>, out NativeArray\<Byte>, out NativeArray\<Byte>)#

Returns the PipelineBuffers for a specific pipeline and stage.

Declaration#

public void GetPipelineBuffers(NetworkPipeline pipeline, NetworkPipelineStageId stageId, NetworkConnection connection, out NativeArray<byte> readProcessingBuffer, out NativeArray<byte> writeProcessingBuffer, out NativeArray<byte> sharedBuffer)

Parameters#

TypeNameDescription
NetworkPipelinepipelinePipeline for which to get the buffers.
NetworkPipelineStageIdstageIdPipeline for which to get the buffers.
NetworkConnectionconnectionConnection for which to the buffers.
NativeArray\<System.Byte>readProcessingBufferThe buffer used to process read (receive) operations.
NativeArray\<System.Byte>writeProcessingBufferThe buffer used to process write (send) operations.
NativeArray\<System.Byte>sharedBufferThe buffer containing the internal state of the pipeline stage.

Exceptions#

TypeCondition
System.InvalidOperationExceptionIf the the connection is invalid.

Listen()#

Set the driver to Listen for incoming connections

Declaration#

public int Listen()

Returns#

TypeDescription
System.Int32Returns 0 on success.

Exceptions#

TypeCondition
System.InvalidOperationExceptionIf the driver is not created properly
System.InvalidOperationExceptionIf listen is called more then once on the driver
System.InvalidOperationExceptionIf bind has not been called before calling Listen.

LocalEndPoint()#

Returns local NetworkEndPoint

Declaration#

public NetworkEndPoint LocalEndPoint()

Returns#

TypeDescription
NetworkEndPointThe network end point

MaxHeaderSize(NetworkPipeline)#

Max headersize including optional NetworkPipeline

Declaration#

public int MaxHeaderSize(NetworkPipeline pipe)

Parameters#

TypeNameDescription
NetworkPipelinepipeThe pipeline for which to get the maximum header size.

Returns#

TypeDescription
System.Int32The maximum header size.

PinMemoryTillUpdate(Int32)#

Moves 'head' of allocator for 'length' bytes. Use this to 'pin' memory in till the next update. If you don't call it - it is 'pinned' till the next call to AllocateMemory(ref Int32) Means every time you call AllocateMemory(ref Int32) without PinMemoryTillUpdate(Int32) memory is overriden

Declaration#

public int PinMemoryTillUpdate(int length)

Parameters#

TypeNameDescription
System.Int32lengthBytes to move

Returns#

TypeDescription
System.Int32Returns head of pinned memory

PopEvent(out NetworkConnection, out DataStreamReader)#

Declaration#

public NetworkEvent.Type PopEvent(out NetworkConnection con, out DataStreamReader reader)

Parameters#

TypeNameDescription
NetworkConnectioncon
DataStreamReaderreader

Returns#

TypeDescription
NetworkEvent.Type

PopEvent(out NetworkConnection, out DataStreamReader, out NetworkPipeline)#

Pops an event

Declaration#

public NetworkEvent.Type PopEvent(out NetworkConnection con, out DataStreamReader reader, out NetworkPipeline pipeline)

Parameters#

TypeNameDescription
NetworkConnectionconConnection on which the event occured.
DataStreamReaderreaderStream reader for the event's data.
NetworkPipelinepipelinePipeline on which the event was received.

Returns#

TypeDescription
NetworkEvent.TypeThe event's type

PopEventForConnection(NetworkConnection, out DataStreamReader)#

Declaration#

public NetworkEvent.Type PopEventForConnection(NetworkConnection connectionId, out DataStreamReader reader)

Parameters#

TypeNameDescription
NetworkConnectionconnectionId
DataStreamReaderreader

Returns#

TypeDescription
NetworkEvent.Type

PopEventForConnection(NetworkConnection, out DataStreamReader, out NetworkPipeline)#

Pops an event for a specific connection

Declaration#

public NetworkEvent.Type PopEventForConnection(NetworkConnection connectionId, out DataStreamReader reader, out NetworkPipeline pipeline)

Parameters#

TypeNameDescription
NetworkConnectionconnectionIdConnection for which to pop the next event.
DataStreamReaderreaderStream reader for the event's data.
NetworkPipelinepipelinePipeline on which the event was received.

Returns#

TypeDescription
NetworkEvent.TypeThe event's type

RemoteEndPoint(NetworkConnection)#

Declaration#

public NetworkEndPoint RemoteEndPoint(NetworkConnection id)

Parameters#

TypeNameDescription
NetworkConnectionid

Returns#

TypeDescription
NetworkEndPoint

ScheduleFlushSend(JobHandle)#

Schedules flushing the sendqueue. Should be called in cases where you want the driver to send before the next ScheduleUpdate(JobHandle) is called.

Declaration#

public JobHandle ScheduleFlushSend(JobHandle dep)

Parameters#

TypeNameDescription
JobHandledepJob on which to depend.

Returns#

TypeDescription
JobHandleThe job handle

ScheduleUpdate(JobHandle)#

Schedules update for driver. This should be called once a frame.

Declaration#

public JobHandle ScheduleUpdate(JobHandle dep = null)

Parameters#

TypeNameDescription
JobHandledepJob on which to depend.

Returns#

TypeDescription
JobHandleThe update job's handle

ToConcurrent()#

Create a Concurrent Copy of the NetworkDriver.

Declaration#

public NetworkDriver.Concurrent ToConcurrent()

Returns#

TypeDescription
NetworkDriver.Concurrent

Implements#

System.IDisposable