Show / Hide Table of Contents

# Class NetPeer

Network peer. Main purpose is sending messages to specific peer.

##### Inheritance

object
EndPoint
IPEndPoint
NetPeer

##### Inherited Members

IPEndPoint.MaxPort
IPEndPoint.MinPort
IPEndPoint.Create(SocketAddress)
IPEndPoint.Equals(object)
IPEndPoint.ToString()
IPEndPoint.Address
IPEndPoint.AddressFamily
IPEndPoint.Port

###### Namespace: LiteNetLib

###### Assembly: LiteNetLib.dll

##### Syntax

    public class NetPeer : 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 NetManager NetManager

##### Field Value

Type | Description
--- | ---
NetManager |

#### 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

#### 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)

##### Declaration

    public int TimeSinceLastPacket { get; }

##### Property Value

Type | Description
--- | ---
int |

### Methods

#### CreatePacketFromPool(DeliveryMethod, byte)

Create temporary packet (maximum size MTU - headerSize) to send later without additional copies

##### Declaration

    public PooledPacket CreatePacketFromPool(DeliveryMethod deliveryMethod, byte channelNumber)

##### Parameters

Type | Name | Description
--- | --- | ---
DeliveryMethod | deliveryMethod | Delivery method (reliable, unreliable, etc.)
byte | channelNumber | Number of channel (from 0 to channelsCount - 1)

##### 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

IPEndPoint.GetHashCode()

#### 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(byte, bool)

Returns packets count in queue for reliable channel

##### Declaration

    public int GetPacketsCountInReliableQueue(byte channelNumber, bool ordered)

##### Parameters

Type | Name | Description
--- | --- | ---
byte | channelNumber | number of channel 0-63
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(NetDataWriter, byte, DeliveryMethod)

Send data to peer

##### Declaration

    public void Send(NetDataWriter dataWriter, byte channelNumber, DeliveryMethod deliveryMethod)

##### Parameters

Type | Name | Description
--- | --- | ---
NetDataWriter | dataWriter | DataWriter with data
byte | channelNumber | Number of channel (from 0 to channelsCount - 1)
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[], byte, DeliveryMethod)

Send data to peer

##### Declaration

    public void Send(byte[] data, byte channelNumber, DeliveryMethod deliveryMethod)

##### Parameters

Type | Name | Description
--- | --- | ---
byte[] | data | Data
byte | channelNumber | Number of channel (from 0 to channelsCount - 1)
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

#### Send(ReadOnlySpan<byte>, byte, DeliveryMethod)

Send data to peer

##### Declaration

    public void Send(ReadOnlySpan<byte> data, byte channelNumber, DeliveryMethod deliveryMethod)

##### Parameters

Type | Name | Description
--- | --- | ---
ReadOnlySpan<byte> | data | Data
byte | channelNumber | Number of channel (from 0 to channelsCount - 1)
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

#### 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, byte, DeliveryMethod, object)

Send data to peer with delivery event called

##### Declaration

    public void SendWithDeliveryEvent(NetDataWriter dataWriter, byte channelNumber, DeliveryMethod deliveryMethod, object userData)

##### Parameters

Type | Name | Description
--- | --- | ---
NetDataWriter | dataWriter | Data
byte | channelNumber | Number of channel (from 0 to channelsCount - 1)
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[], byte, DeliveryMethod, object)

Send data to peer with delivery event called

##### Declaration

    public void SendWithDeliveryEvent(byte[] data, byte channelNumber, DeliveryMethod deliveryMethod, object userData)

##### Parameters

Type | Name | Description
--- | --- | ---
byte[] | data | Data
byte | channelNumber | Number of channel (from 0 to channelsCount - 1)
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, byte, DeliveryMethod, object)

Send data to peer with delivery event called

##### Declaration

    public void SendWithDeliveryEvent(byte[] data, int start, int length, byte channelNumber, DeliveryMethod deliveryMethod, object userData)

##### 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.)
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>, byte, DeliveryMethod, object)

Send data to peer with delivery event called

##### Declaration

    public void SendWithDeliveryEvent(ReadOnlySpan<byte> data, byte channelNumber, DeliveryMethod deliveryMethod, object userData)

##### Parameters

Type | Name | Description
--- | --- | ---
ReadOnlySpan<byte> | data | Data
byte | channelNumber | Number of channel (from 0 to channelsCount - 1)
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

IPEndPoint.Serialize()