Struct NetworkDriver
The NetworkDriver
is the main API with which users interact with the Unity Transport
package. It can be thought of as a socket with extra features. Refer to the manual for
examples of how to use this API.
Implements
Inherited Members
Namespace: Unity.Networking.Transport
Assembly: solution.dll
Syntax
public struct NetworkDriver : IDisposable
Constructors
Name | Description |
---|---|
NetworkDriver(INetworkInterface) | Use Create(NetworkSettings) to construct |
NetworkDriver(INetworkInterface, NetworkSettings) | Use Create(NetworkSettings) to construct |
Properties
Name | Description |
---|---|
Bound | Whether the driver has been bound to an endpoint with the Bind(NetworkEndpoint) method. Binding to an endpoint is a prerequisite to listening to new connections (with the Listen() method). It is also a prerequiste to making new connections, but the Connect(NetworkEndpoint) method will automatically bind the driver to the wildcard address if it's not already bound. |
CurrentSettings | Current settings used by the driver. |
IsCreated | Whether the driver is been correctly created. |
Listening | Whether the driver is listening for new connections (e.g. acting like a server). Use the Listen() method to start listening for new connections. |
ReceiveErrorCode | Error code raised by the last receive job, if any. |
Methods
Name | Description |
---|---|
AbortSend(DataStreamWriter) | Aborts a send started with BeginSend(NetworkPipeline, NetworkConnection, out DataStreamWriter, int). |
Accept() | Accept any new incoming connections. Connections must be accepted before data can be sent on them. It's also the only way to obtain the NetworkConnection value for new connections on servers. |
BeginSend(NetworkConnection, out DataStreamWriter, int) | Begin sending data on the given connection (default pipeline). |
BeginSend(NetworkPipeline, NetworkConnection, out DataStreamWriter, int) | Begin sending data on the given connection and pipeline. |
Bind(NetworkEndpoint) | Bind the driver to an endpoint. This endpoint would normally be a local IP address and port which the driver will use for its communications. Binding to a wildcard address (AnyIpv4 or AnyIpv6) will result in the driver using any local address for its communications, and binding to port 0 will result in the driver using an ephemeral free port chosen by the OS. |
Connect(NetworkEndpoint) | Establish a new connection to the given endpoint. Note that this only starts establishing the new connection. From there it will either succeeds (a Connect event will pop on the connection) or fail (a Disconnect event will pop on the connection) at a later time. |
Create() | Create a new |
Create(NetworkSettings) | Create a new |
CreatePipeline(params Type[]) | Create a new pipeline from stage types. |
CreatePipeline(NativeArray<NetworkPipelineStageId>) | Create a new pipeline from stage IDs. |
Create<N>(N) | Create a new |
Create<N>(N, NetworkSettings) | Create a new |
Create<N>(ref N) | Create a new |
Create<N>(ref N, NetworkSettings) | Create a new |
Disconnect(NetworkConnection) | Close a connection. Note that to properly notify a peer of this disconnection, it is required to schedule at least one update with ScheduleUpdate(JobHandle) and complete it. Failing to do could leave the remote peer unaware that the connection has been closed (however it will time out on its own after a while). |
Dispose() | Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. |
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). |
GetConnectionState(NetworkConnection) | Get the current state of the given connection. |
GetEventQueueSizeForConnection(NetworkConnection) | Returns the size of the event queue for a specific connection. This is the number of events that could be popped with PopEventForConnection(NetworkConnection, out DataStreamReader). |
GetLocalEndpoint() | Get the local endpoint used by the driver (the endpoint remote peers will use to reach this driver). |
GetPipelineBuffers(NetworkPipeline, NetworkPipelineStageId, NetworkConnection, out NativeArray<byte>, out NativeArray<byte>, out NativeArray<byte>) | Get the low-level pipeline buffers for a given pipeline stage on a given pipeline and for a given connection. Can be used to extract information from a pipeline at runtime. Note that this is a low-level API which is not recommended for general use. |
GetRemoteEndpoint(NetworkConnection) | Get the remote endpoint of a connection (the endpoint used to reach the remote peer on the connection). |
Listen() | Set the driver to Listen for incomming connections |
LocalEndPoint() | Obsolete. Use GetLocalEndpoint() instead. |
MaxHeaderSize(NetworkPipeline) | Get the maximum size of headers when sending on the given pipeline. |
PopEvent(out NetworkConnection, out DataStreamReader) | Pops the next event from the event queue, Empty will be returned if there are no more events to pop. |
PopEvent(out NetworkConnection, out DataStreamReader, out NetworkPipeline) | Pops the next event from the event queue, Empty will be returned if there are no more events to pop. |
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. |
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. |
RegisterPipelineStage<T>(T) | Register a custom pipeline stage. |
RemoteEndPoint(NetworkConnection) | Obsolete. Use GetRemoteEndpoint(NetworkConnection) instead. |
ScheduleFlushSend(JobHandle) | Schedule a send job. This job is basically a subset of the update job (see ScheduleUpdate(JobHandle)) and only takes care of sending packets queued with EndSend(DataStreamWriter). It should be lightweight enough to schedule multiple times per tick to improve latency if there's a significant amount of packets being sent. |
ScheduleUpdate(JobHandle) | Schedule an update job. This job will process incoming packets and check timeouts (queueing up the relevant events to be consumed by PopEvent(out NetworkConnection, out DataStreamReader) and Accept()) and will send any packets queued with EndSend(DataStreamWriter). This job should generally be scheduled once per tick. |
ToConcurrent() | Create a NetworkDriver.Concurrent copy of the |