Struct NetworkStreamDriver
Singleton that can hold a reference to the NetworkDriverStore and that should be used to easily listening for new connection or connecting to server. Provide also other shortcut for retrieving the remote address of a NetworkStreamConnection or its underlying transport state.
Inherited Members
Namespace: Unity.NetCode
Syntax
public struct NetworkStreamDriver : IComponentData, IQueryTypeParameter
Methods
Connect(EntityManager, NetworkEndpoint, Entity)
Initiate a connection to the remote endpoint address.
Declaration
public Entity Connect(EntityManager entityManager, NetworkEndpoint endpoint, Entity ent = default(Entity))
Parameters
| Type | Name | Description |
|---|---|---|
| EntityManager | entityManager | The entity manager to use to create the new entity, if |
| NetworkEndpoint | 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 NetworkStreamConnection. If the endpoint is not valid |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | 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 |
|---|---|---|
| NetworkStreamConnection | connection |
Returns
| Type | Description |
|---|---|
| NetworkConnection.State |
Remarks
Is different from the ConnectionState.State and it is less granular.
GetLocalEndPoint()
Get the local endpoint (the endpoint remote peers will use to reach this driver) used by the first driver inside NetworkDriverStore. This is similar to calling GetLocalEndPoint(Int32) with FirstDriverId as argument.
Declaration
public NetworkEndpoint GetLocalEndPoint()
Returns
| Type | Description |
|---|---|
| NetworkEndpoint | The local endpoint of the first driver. |
GetLocalEndPoint(Int32)
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 NetworkDriverStore.
Declaration
public NetworkEndpoint GetLocalEndPoint(int driverId)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | driverId | Id of the driver. See GetNetworkDriver(Int32) |
Returns
| Type | Description |
|---|---|
| NetworkEndpoint | 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 |
|---|---|---|
| NetworkStreamConnection | connection |
Returns
| Type | Description |
|---|---|
| NetworkEndpoint | 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 GetRemoteEndpoint(NetworkConnection) does not always return a valid address when used with relay (once the connection is established it become the RelayAllocationId). We instead wanted a consistent behaviour for this method: always return the address to which this connection is is connected/connecting to.
Listen(NetworkEndpoint)
Tell all the registered NetworkDriverStore drivers to start listening for incoming connections.
Declaration
public bool Listen(NetworkEndpoint endpoint)
Parameters
| Type | Name | Description |
|---|---|---|
| NetworkEndpoint | endpoint | The local address to use. This is the address that will be used to bind the underlying socket. |
Returns
| Type | Description |
|---|---|
| Boolean |
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 |
|---|---|---|
| NetworkStreamConnection | connection |
Returns
| Type | Description |
|---|---|
| Boolean | Either if the connection is using the relay or not. |