Show / Hide Table of Contents

Class NetPeer

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

Inheritance
System.Object
NetPeer
Namespace: LiteNetLib
Assembly: LiteNetLib.dll
Syntax
public class NetPeer

Fields

EndPoint

Peer ip address and port

Declaration
public readonly IPEndPoint EndPoint
Field Value
Type Description
System.Net.IPEndPoint

Id

Peer id can be used as key in your dictionary of peers

Declaration
public readonly int Id
Field Value
Type Description
System.Int32

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
System.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
System.Int32

Ping

Current ping in milliseconds

Declaration
public int Ping { get; }
Property Value
Type Description
System.Int32

RemoteTimeDelta

Delta with remote time in ticks (not accurate) positive - remote time > our time

Declaration
public long RemoteTimeDelta { get; }
Property Value
Type Description
System.Int64

RemoteUtcTime

Remote UTC time (not accurate)

Declaration
public DateTime RemoteUtcTime { get; }
Property Value
Type Description
System.DateTime

TimeSinceLastPacket

Time since last packet received (including internal library packets)

Declaration
public int TimeSinceLastPacket { get; }
Property Value
Type Description
System.Int32

Methods

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
System.Byte[] data

Disconnect(Byte[], Int32, Int32)

Declaration
public void Disconnect(byte[] data, int start, int count)
Parameters
Type Name Description
System.Byte[] data
System.Int32 start
System.Int32 count

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
System.Int32

size in bytes

GetPacketsCountInReliableQueue(Byte, Boolean)

Returns packets count in queue for reliable channel

Declaration
public int GetPacketsCountInReliableQueue(byte channelNumber, bool ordered)
Parameters
Type Name Description
System.Byte channelNumber

number of channel 0-63

System.Boolean ordered

type of channel ReliableOrdered or ReliableUnordered

Returns
Type Description
System.Int32

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

System.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
System.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
System.Byte[] data

Data

System.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[], Int32, Int32, DeliveryMethod)

Send data to peer (channel - 0)

Declaration
public void Send(byte[] data, int start, int length, DeliveryMethod options)
Parameters
Type Name Description
System.Byte[] data

Data

System.Int32 start

Start of data

System.Int32 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[], Int32, Int32, Byte, DeliveryMethod)

Send data to peer

Declaration
public void Send(byte[] data, int start, int length, byte channelNumber, DeliveryMethod deliveryMethod)
Parameters
Type Name Description
System.Byte[] data

Data

System.Int32 start

Start of data

System.Int32 length

Length of data

System.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

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

System.Byte channelNumber

Number of channel (from 0 to channelsCount - 1)

DeliveryMethod deliveryMethod

Delivery method (reliable, unreliable, etc.)

System.Object userData

User data that will be received in DeliveryEvent

Exceptions
Type Condition
System.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
System.Byte[] data

Data

System.Byte channelNumber

Number of channel (from 0 to channelsCount - 1)

DeliveryMethod deliveryMethod

Delivery method (reliable, unreliable, etc.)

System.Object userData

User data that will be received in DeliveryEvent

Exceptions
Type Condition
System.ArgumentException

If you trying to send unreliable packet type

SendWithDeliveryEvent(Byte[], Int32, Int32, 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
System.Byte[] data

Data

System.Int32 start

Start of data

System.Int32 length

Length of data

System.Byte channelNumber

Number of channel (from 0 to channelsCount - 1)

DeliveryMethod deliveryMethod

Delivery method (reliable, unreliable, etc.)

System.Object userData

User data that will be received in DeliveryEvent

Exceptions
Type Condition
System.ArgumentException

If you trying to send unreliable packet type

In This Article
Back to top Generated by DocFX