Interface INetworkInterface
Network interfaces are the lowest level of the Unity Transport library. They are responsible for sending and receiving packets directly to/from the network. Conceptually, they act like sockets. Users can provide their own network interfaces by implementing this interface and passing a new instance of it to Create<N>(N).
Note that network interfaces are expected to be unmanaged types compatible with Burst.
However, it is possible to write them using managed types and code. Simply wrap them with
Wrap
Inherited Members
Namespace: Unity.Networking.Transport
Assembly: Unity.Networking.Transport.dll
Syntax
public interface INetworkInterface : IDisposable
Properties
LocalEndpoint
Gets the local endpoint that the interface will use to communicate on the network.
This call only makes sense after Bind(Networkgetsockname
in the BSD socket world.
Declaration
NetworkEndpoint LocalEndpoint { get; }
Property Value
Type | Description |
---|---|
Network |
Local endpoint. |
Methods
Bind(NetworkEndpoint)
Binds the network interface to an endpoint. This is meant to act the same way as the
bind
call in the BSD socket world. One way to see it is that it "attaches" the
network interface to a specific local address on the machine.
Declaration
int Bind(NetworkEndpoint endpoint)
Parameters
Type | Name | Description |
---|---|---|
Network |
endpoint | Endpoint to bind to. |
Returns
Type | Description |
---|---|
int | 0 on success, a negative number on error. |
Initialize(ref NetworkSettings, ref int)
Initialize the network interface with the given settings.
Declaration
int Initialize(ref NetworkSettings settings, ref int packetPadding)
Parameters
Type | Name | Description |
---|---|---|
Network |
settings | Configuration settings provided to the driver. |
int | packetPadding | Return value parameter for how much padding the interface adds to packets. Note that this parameter is only concerned about padding that would be added directly in the packets stored in the send and receive queues, not to padding that would be added by lower levels of the network stack (e.g. IP headers). |
Returns
Type | Description |
---|---|
int | 0 on success, a negative number on error. |
Listen()
Start listening for incoming connections. Unlike Bind(Network
Declaration
int Listen()
Returns
Type | Description |
---|---|
int | 0 on success, a negative number on error. |
ScheduleReceive(ref ReceiveJobArguments, JobHandle)
Schedule a receive job. This job's responsibility is to read data from the network and
enqueue it in Receive
Declaration
JobHandle ScheduleReceive(ref ReceiveJobArguments arguments, JobHandle dep)
Parameters
Type | Name | Description |
---|---|---|
Receive |
arguments | Arguments to be passed to the receive job. |
Job |
dep | Handle to any dependency the receive job has (use default if none). |
Returns
Type | Description |
---|---|
Job |
Handle to the newly-schedule job. |
ScheduleSend(ref SendJobArguments, JobHandle)
Schedule a send job. This job's responsibility is to flush any data stored in
Send
Declaration
JobHandle ScheduleSend(ref SendJobArguments arguments, JobHandle dep)
Parameters
Type | Name | Description |
---|---|---|
Send |
arguments | Arguments to be passed to the send job. |
Job |
dep | Handle to any dependency the send job has (use default if none). |
Returns
Type | Description |
---|---|
Job |
Handle to the newly-schedule job. |