Struct IPCNetworkInterface
The IPC network interface implements the functionality of a network interface over an in-memory buffer. Operations will be instantaneous, but can only be used to communicate with other NetworkDriver instances inside the same process (so IPC really means intra-process and not inter-process here). Useful for testing, or to implement a single player mode in a multiplayer game.
Note that the interface expects loopback addresses when binding/connecting. It is recommended to only use LoopbackIpv4 when dealing with the IPC network interface, and to use different ports for different drivers (see example).
Inherited Members
Namespace: Unity.Networking.Transport
Assembly: solution.dll
Syntax
[BurstCompile]
public struct IPCNetworkInterface : INetworkInterface, IDisposable
Examples
This example code establishes an in-process communication channel between two drivers:
var driver1 = NetworkDriver.Create(new IPCNetworkInterface());
driver1.Bind(NetworkEndpoint.LoopbackIpv4.WithPort(1));
driver1.Listen();
var driver2 = NetworkDriver.Create(new IPCNetworkInterface());
driver2.Bind(NetworkEndpoint.LoopbackIpv4.WithPort(2));
var connection2to1 = driver2.Connect(NetworkEndpoint.LoopbackIpv4.WithPort(1));
// Need to schedule updates for driver2 to send the connection request, and for
// driver1 to then process it. Since this all happens in-memory, one update is
// sufficient to accomplish this (no network latency involved).
driver2.ScheduleUpdate().Complete();
driver1.ScheduleUpdate().Complete();
var connection1to2 = driver1.Accept();
Properties
Name | Description |
---|---|
LocalEndpoint | Gets the local endpoint that the interface will use to communicate on the network.
This call only makes sense after Bind(NetworkEndpoint) has already been called, and
represents the endpoint the interface is actually bound to. This property serves the
same purpose as |
Methods
Name | Description |
---|---|
Bind(NetworkEndpoint) | Binds the network interface to an endpoint. This is meant to act the same way as the
|
Dispose() | Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. |
Initialize(ref NetworkSettings, ref int) | Initialize the network interface with the given settings. |
Listen() | Start listening for incoming connections. Unlike Bind(NetworkEndpoint) which will always be called on clients and servers, this is only meant to be called on servers. |
ScheduleReceive(ref ReceiveJobArguments, JobHandle) | Schedule a receive job. This job's responsibility is to read data from the network and enqueue it in ReceiveQueue. |
ScheduleSend(ref SendJobArguments, JobHandle) | Schedule a send job. This job's responsibility is to flush any data stored in SendQueue to the network. |