Struct NetworkStreamDriver
Singleton that can hold a reference to the Network
Implements
Inherited Members
Namespace: Unity.NetCode
Assembly: Unity.NetCode.dll
Syntax
public struct NetworkStreamDriver : IComponentData, IQueryTypeParameter
Properties
ConnectionEventsForTick
Stores all Net
Declaration
public readonly NativeArray<NetCodeConnectionEvent>.ReadOnly ConnectionEventsForTick { get; }
Property Value
Type | Description |
---|---|
Native |
Remarks
Because events are only valid for a single tick, any code that reads from (i.e. consumes) these events must
update in the Unity.
Methods
Connect(EntityManager, NetworkEndpoint, Entity)
Initiate a connection to the remote endpoint
address.
Declaration
public Entity Connect(EntityManager entityManager, NetworkEndpoint endpoint, Entity ent = default)
Parameters
Type | Name | Description |
---|---|---|
Entity |
entityManager | The entity manager to use to create the new entity, if |
Network |
endpoint | The remote address we want to connect |
Entity | ent | An optional entity to use to create the connection. If not set, a new entity will be create instead |
Returns
Type | Description |
---|---|
Entity | The entity that hold the Network |
Exceptions
Type | Condition |
---|---|
Invalid |
Throw an exception if the driver is not created or if multiple drivers are register |
GetConnectionState(NetworkStreamConnection)
The current state of the internal transport connection.
Declaration
public NetworkConnection.State GetConnectionState(NetworkStreamConnection connection)
Parameters
Type | Name | Description |
---|---|---|
Network |
connection |
Returns
Type | Description |
---|---|
Network |
Remarks
Is different from the Connection
GetLocalEndPoint()
Get the local endpoint (the endpoint remote peers will use to reach this driver) used by the first driver inside Network
Declaration
public NetworkEndpoint GetLocalEndPoint()
Returns
Type | Description |
---|---|
Network |
The local endpoint of the first driver. |
GetLocalEndPoint(int)
Get the local endpoint used by the driver (the endpoint remote peers will use to reach this driver).
When multiple drivers exist, e.g. when using both IPC and Socket connection, multiple drivers will be available
in the Network
Declaration
public NetworkEndpoint GetLocalEndPoint(int driverId)
Parameters
Type | Name | Description |
---|---|---|
int | driverId | Id of the driver. See Get |
Returns
Type | Description |
---|---|
Network |
The local endpoint of the driver. |
GetRemoteEndPoint(NetworkStreamConnection)
The remote connection address. This is the seen public ip address of the connection.
Declaration
public NetworkEndpoint GetRemoteEndPoint(NetworkStreamConnection connection)
Parameters
Type | Name | Description |
---|---|---|
Network |
connection |
Returns
Type | Description |
---|---|
Network |
When relay is used, the current relay host address. Otherwise the remote endpoint address. |
Remarks
Be aware that this method work sliglty differnetly than the NetworkDriver.GetRemoteEndpoint.
The Unity.
Listen(NetworkEndpoint)
Tell all the registered Network
Declaration
public bool Listen(NetworkEndpoint endpoint)
Parameters
Type | Name | Description |
---|---|---|
Network |
endpoint | The local address to use. This is the address that will be used to bind the underlying socket. |
Returns
Type | Description |
---|---|
bool |
UseRelay(NetworkStreamConnection)
Check if the given connection is using relay to connect to the remote endpoint
Declaration
public bool UseRelay(NetworkStreamConnection connection)
Parameters
Type | Name | Description |
---|---|---|
Network |
connection |
Returns
Type | Description |
---|---|
bool | Either if the connection is using the relay or not. |