Class LiteNetPeer
Network peer. Main purpose is sending messages to specific peer.
Inherited Members
Namespace: LiteNetLib
Assembly: LiteNetLib.dll
Syntax
public class LiteNetPeer : IPEndPoint
Fields
Id
Peer id can be used as key in your dictionary of peers
Declaration
public readonly int Id
Field Value
| Type | Description |
|---|---|
| int |
NetManager
Peer parent NetManager
Declaration
public readonly LiteNetManager NetManager
Field Value
| Type | Description |
|---|---|
| LiteNetManager |
Statistics
Statistics of peer connection
Declaration
public readonly NetStatistics Statistics
Field Value
| Type | Description |
|---|---|
| NetStatistics |
Tag
Application defined object containing data about the connection
Declaration
public object Tag
Field Value
| Type | Description |
|---|---|
| object |
Properties
ChannelsCount
Declaration
protected virtual int ChannelsCount { get; }
Property Value
| Type | Description |
|---|---|
| int |
ConnectionState
Current connection state
Declaration
public ConnectionState ConnectionState { get; }
Property Value
| Type | Description |
|---|---|
| ConnectionState |
Mtu
Current MTU - Maximum Transfer Unit ( maximum udp packet size without fragmentation )
Declaration
public int Mtu { get; }
Property Value
| Type | Description |
|---|---|
| int |
Ping
Current one-way ping (RTT/2) in milliseconds
Declaration
public int Ping { get; }
Property Value
| Type | Description |
|---|---|
| int |
RemoteId
Id assigned from server
Declaration
public int RemoteId { get; }
Property Value
| Type | Description |
|---|---|
| int |
RemoteTimeDelta
Delta with remote time in ticks (not accurate) positive - remote time > our time
Declaration
public long RemoteTimeDelta { get; }
Property Value
| Type | Description |
|---|---|
| long |
RemoteUtcTime
Remote UTC time (not accurate)
Declaration
public DateTime RemoteUtcTime { get; }
Property Value
| Type | Description |
|---|---|
| DateTime |
RoundTripTime
Round trip time in milliseconds
Declaration
public int RoundTripTime { get; }
Property Value
| Type | Description |
|---|---|
| int |
TimeSinceLastPacket
Time since last packet received (including internal library packets) in milliseconds
Declaration
public float TimeSinceLastPacket { get; }
Property Value
| Type | Description |
|---|---|
| float |
Methods
CreatePacketFromPool(DeliveryMethod)
Create temporary packet (maximum size MTU - headerSize) to send later without additional copies
Declaration
public PooledPacket CreatePacketFromPool(DeliveryMethod deliveryMethod)
Parameters
| Type | Name | Description |
|---|---|---|
| DeliveryMethod | deliveryMethod | Delivery method (reliable, unreliable, etc.) |
Returns
| Type | Description |
|---|---|
| PooledPacket | PooledPacket that you can use to write data starting from UserDataOffset |
Disconnect()
Declaration
public void Disconnect()
Disconnect(NetDataWriter)
Declaration
public void Disconnect(NetDataWriter writer)
Parameters
| Type | Name | Description |
|---|---|---|
| NetDataWriter | writer |
Disconnect(byte[])
Declaration
public void Disconnect(byte[] data)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | data |
Disconnect(byte[], int, int)
Declaration
public void Disconnect(byte[] data, int start, int count)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | data | |
| int | start | |
| int | count |
GetHashCode()
Returns a hash value for a IPEndPoint instance.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| int | An integer hash value. |
Overrides
GetMaxSinglePacketSize(DeliveryMethod)
Gets maximum size of packet that will be not fragmented.
Declaration
public int GetMaxSinglePacketSize(DeliveryMethod options)
Parameters
| Type | Name | Description |
|---|---|---|
| DeliveryMethod | options | Type of packet that you want send |
Returns
| Type | Description |
|---|---|
| int | size in bytes |
GetPacketsCountInReliableQueue(bool)
Returns packets count in queue for reliable channel 0
Declaration
public int GetPacketsCountInReliableQueue(bool ordered)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | ordered | type of channel ReliableOrdered or ReliableUnordered |
Returns
| Type | Description |
|---|---|
| int | packets count in channel queue |
Send(NetDataWriter, DeliveryMethod)
Send data to peer (channel - 0)
Declaration
public void Send(NetDataWriter dataWriter, DeliveryMethod deliveryMethod)
Parameters
| Type | Name | Description |
|---|---|---|
| NetDataWriter | dataWriter | DataWriter with data |
| DeliveryMethod | deliveryMethod | Send options (reliable, unreliable, etc.) |
Exceptions
| Type | Condition |
|---|---|
| TooBigPacketException | If size exceeds maximum limit: MTU - headerSize bytes for Unreliable Fragment count exceeded ushort.MaxValue |
Send(byte[], DeliveryMethod)
Send data to peer (channel - 0)
Declaration
public void Send(byte[] data, DeliveryMethod deliveryMethod)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | data | Data |
| DeliveryMethod | deliveryMethod | Send options (reliable, unreliable, etc.) |
Exceptions
| Type | Condition |
|---|---|
| TooBigPacketException | If size exceeds maximum limit: MTU - headerSize bytes for Unreliable Fragment count exceeded ushort.MaxValue |
Send(byte[], int, int, DeliveryMethod)
Send data to peer (channel - 0)
Declaration
public void Send(byte[] data, int start, int length, DeliveryMethod options)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | data | Data |
| int | start | Start of data |
| int | length | Length of data |
| DeliveryMethod | options | Send options (reliable, unreliable, etc.) |
Exceptions
| Type | Condition |
|---|---|
| TooBigPacketException | If size exceeds maximum limit: MTU - headerSize bytes for Unreliable Fragment count exceeded ushort.MaxValue |
Send(byte[], int, int, byte, DeliveryMethod)
Send data to peer
Declaration
public void Send(byte[] data, int start, int length, byte channelNumber, DeliveryMethod deliveryMethod)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | data | Data |
| int | start | Start of data |
| int | length | Length of data |
| byte | channelNumber | Number of channel (from 0 to channelsCount - 1) |
| DeliveryMethod | deliveryMethod | Delivery method (reliable, unreliable, etc.) |
Exceptions
| Type | Condition |
|---|---|
| TooBigPacketException | If size exceeds maximum limit: MTU - headerSize bytes for Unreliable Fragment count exceeded ushort.MaxValue |
Send(ReadOnlySpan<byte>, DeliveryMethod)
Send data to peer (channel - 0)
Declaration
public void Send(ReadOnlySpan<byte> data, DeliveryMethod deliveryMethod)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<byte> | data | Data |
| DeliveryMethod | deliveryMethod | Send options (reliable, unreliable, etc.) |
Exceptions
| Type | Condition |
|---|---|
| TooBigPacketException | If size exceeds maximum limit: MTU - headerSize bytes for Unreliable Fragment count exceeded ushort.MaxValue |
SendInternal(ReadOnlySpan<byte>, byte, DeliveryMethod, object)
Declaration
protected void SendInternal(ReadOnlySpan<byte> data, byte channelNumber, DeliveryMethod deliveryMethod, object userData)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<byte> | data | |
| byte | channelNumber | |
| DeliveryMethod | deliveryMethod | |
| object | userData |
SendPooledPacket(PooledPacket, int)
Sends pooled packet without data copy
Declaration
public void SendPooledPacket(PooledPacket packet, int userDataSize)
Parameters
| Type | Name | Description |
|---|---|---|
| PooledPacket | packet | packet to send |
| int | userDataSize | size of user data you want to send |
SendWithDeliveryEvent(NetDataWriter, DeliveryMethod, object)
Send data to peer with delivery event called
Declaration
public void SendWithDeliveryEvent(NetDataWriter dataWriter, DeliveryMethod deliveryMethod, object userData)
Parameters
| Type | Name | Description |
|---|---|---|
| NetDataWriter | dataWriter | Data |
| DeliveryMethod | deliveryMethod | Delivery method (reliable, unreliable, etc.) |
| object | userData | User data that will be received in DeliveryEvent |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | If you trying to send unreliable packet type |
SendWithDeliveryEvent(byte[], DeliveryMethod, object)
Send data to peer with delivery event called
Declaration
public void SendWithDeliveryEvent(byte[] data, DeliveryMethod deliveryMethod, object userData)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | data | Data |
| DeliveryMethod | deliveryMethod | Delivery method (reliable, unreliable, etc.) |
| object | userData | User data that will be received in DeliveryEvent |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | If you trying to send unreliable packet type |
SendWithDeliveryEvent(byte[], int, int, DeliveryMethod, object)
Send data to peer with delivery event called
Declaration
public void SendWithDeliveryEvent(byte[] data, int start, int length, DeliveryMethod deliveryMethod, object userData)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | data | Data |
| int | start | Start of data |
| int | length | Length of data |
| DeliveryMethod | deliveryMethod | Delivery method (reliable, unreliable, etc.) |
| object | userData | User data that will be received in DeliveryEvent |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | If you trying to send unreliable packet type |
SendWithDeliveryEvent(ReadOnlySpan<byte>, DeliveryMethod, object)
Send data to peer with delivery event called
Declaration
public void SendWithDeliveryEvent(ReadOnlySpan<byte> data, DeliveryMethod deliveryMethod, object userData)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<byte> | data | Data |
| DeliveryMethod | deliveryMethod | Delivery method (reliable, unreliable, etc.) |
| object | userData | User data that will be received in DeliveryEvent |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | If you trying to send unreliable packet type |
Serialize()
IPEndPoint serialize
Declaration
public override SocketAddress Serialize()
Returns
| Type | Description |
|---|---|
| SocketAddress | SocketAddress |
Overrides
UpdateChannels()
Declaration
protected virtual void UpdateChannels()