Struct NetworkConnection
Public representation of a connection. This is obtained by calling Accept() (on servers) or Connect(NetworkEndpoint) (on clients) and acts as a handle to the communication session with a remote peer.
Inherited Members
Namespace: Unity.Networking.Transport
Syntax
public struct NetworkConnection : IEquatable<NetworkConnection>
Properties
IsCreated
Whether the connection was correctly obtained from a call to Accept() or Connect(NetworkEndpoint).
Declaration
public readonly bool IsCreated { get; }
Property Value
| Type | Description |
|---|---|
| Boolean | True if created correctly, false otherwise. |
Methods
Close(NetworkDriver)
Close an active connection. Strictly identical to Disconnect(NetworkDriver).
Declaration
public int Close(NetworkDriver driver)
Parameters
| Type | Name | Description |
|---|---|---|
| NetworkDriver | driver | Driver on which to perform the operation. |
Returns
| Type | Description |
|---|---|
| Int32 | 0 on success, a negative error code otherwise. |
Disconnect(NetworkDriver)
Close an active connection. Strictly identical to Close(NetworkDriver).
Declaration
public int Disconnect(NetworkDriver driver)
Parameters
| Type | Name | Description |
|---|---|---|
| NetworkDriver | driver | Driver on which to perform the operation. |
Returns
| Type | Description |
|---|---|
| Int32 | 0 on success, a negative error code otherwise. |
Equals(Object)
Declaration
public override bool Equals(object o)
Parameters
| Type | Name | Description |
|---|---|---|
| Object | o |
Returns
| Type | Description |
|---|---|
| Boolean |
Overrides
Equals(NetworkConnection)
Declaration
public bool Equals(NetworkConnection o)
Parameters
| Type | Name | Description |
|---|---|---|
| NetworkConnection | o |
Returns
| Type | Description |
|---|---|
| Boolean |
Implements
GetHashCode()
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| Int32 |
Overrides
GetState(NetworkDriver)
Get the current state of a connection.
Declaration
public NetworkConnection.State GetState(NetworkDriver driver)
Parameters
| Type | Name | Description |
|---|---|---|
| NetworkDriver | driver | Driver to get the state from. |
Returns
| Type | Description |
|---|---|
| NetworkConnection.State | Current state of the connection. |
PopEvent(NetworkDriver, out DataStreamReader)
Pop the next available event on the connection.
Declaration
public NetworkEvent.Type PopEvent(NetworkDriver driver, out DataStreamReader stream)
Parameters
| Type | Name | Description |
|---|---|---|
| NetworkDriver | driver | Driver from which to get the event. |
| DataStreamReader | stream | Reader into the data associated to the event. Only populated if the returned event is Data or Disconnect, where respectively the data will be either the received payload, or the disconnection reason (as a single byte). |
Returns
| Type | Description |
|---|---|
| NetworkEvent.Type | Type of the popped event. Empty if nothing to pop. |
PopEvent(NetworkDriver, out DataStreamReader, out NetworkPipeline)
Pop the next available event on the connection.
Declaration
public NetworkEvent.Type PopEvent(NetworkDriver driver, out DataStreamReader stream, out NetworkPipeline pipeline)
Parameters
| Type | Name | Description |
|---|---|---|
| NetworkDriver | driver | Driver from which to get the event. |
| DataStreamReader | stream | Reader into the data associated to the event. Only populated if the returned event is Data or Disconnect, where respectively the data will be either the received payload, or the disconnection reason (as a single byte). |
| NetworkPipeline | pipeline | Pipeline on which the data was received. |
Returns
| Type | Description |
|---|---|
| NetworkEvent.Type | Type of the popped event. Empty if nothing to pop. |
ToFixedString()
Return a fixed string representation of the connection. For use in contexts where ToString() can't be used (e.g. Burst-compiled code).
Declaration
public FixedString128Bytes ToFixedString()
Returns
| Type | Description |
|---|---|
| FixedString128Bytes | Fixed string representation of the connection. |
ToString()
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| String |
Overrides
Operators
Equality(NetworkConnection, NetworkConnection)
Declaration
public static bool operator ==(NetworkConnection lhs, NetworkConnection rhs)
Parameters
| Type | Name | Description |
|---|---|---|
| NetworkConnection | lhs | |
| NetworkConnection | rhs |
Returns
| Type | Description |
|---|---|
| Boolean |
Inequality(NetworkConnection, NetworkConnection)
Declaration
public static bool operator !=(NetworkConnection lhs, NetworkConnection rhs)
Parameters
| Type | Name | Description |
|---|---|---|
| NetworkConnection | lhs | |
| NetworkConnection | rhs |
Returns
| Type | Description |
|---|---|
| Boolean |