Skip to content

Class Lidgren::Network::NetPeer

ClassList > Lidgren > Network > NetPeer

Represents a local peer capable of holding zero, one or more connections to remote peers.

Inherited by the following classes: Lidgren::Network::NetClient, Lidgren::Network::NetServer

Public Properties

Type Name
property NetPeerConfiguration Configuration
Gets the configuration used to instanciate this NetPeer.
property List< NetConnection > Connections
Gets a copy of the list of connections.
property int ConnectionsCount
Gets the number of active connections.
property AutoResetEvent MessageReceivedEvent
Signalling event which can be waited on to determine when a message is queued for reading. Note that there is no guarantee that after the event is signaled the blocked thread will find the message in the queue. Other user created threads could be preempted and dequeue the message before the waiting thread wakes up.
property int Port
Gets the port number this NetPeer is listening and sending on, if Start() has been called.
property Socket Socket
Gets the socket, if Start() has been called.
property NetPeerStatistics Statistics
Statistics on this NetPeer since it was initialized.
property NetPeerStatus Status
Gets the NetPeerStatus of the NetPeer.
property object Tag
Gets or sets the application defined object containing data about the peer.
property NetUPnP UPnP
Returns an UPnP object if enabled in the NetPeerConfiguration.
property long UniqueIdentifier
Gets a unique identifier for this NetPeer based on Mac address and ip/port. Note! Not available until Start() has been called!

Public Functions

Type Name
NetConnection Connect (string host, int port)
Create a connection to a remote endpoint.
NetConnection Connect (string host, int port, NetOutgoingMessage hailMessage)
Create a connection to a remote endpoint.
NetConnection Connect (NetEndPoint remoteEndPoint)
Create a connection to a remote endpoint.
virtual NetConnection Connect (NetEndPoint remoteEndPoint, NetOutgoingMessage hailMessage)
Create a connection to a remote endpoint.
NetOutgoingMessage CreateMessage ()
Creates a new message for sending.
NetOutgoingMessage CreateMessage (string content)
Creates a new message for sending and writes the provided string to it.
NetOutgoingMessage CreateMessage (int initialCapacity)
Creates a new message for sending.
bool DiscoverKnownPeer (string host, int serverPort)
Emit a discovery signal to a single known host.
void DiscoverKnownPeer (NetEndPoint endPoint)
Emit a discovery signal to a single known host.
void DiscoverLocalPeers (int serverPort)
Emit a discovery signal to all hosts on your subnet.
void FlushSendQueue ()
If NetPeerConfiguration.AutoFlushSendQueue() is false; you need to call this to send all messages queued using SendMessage()
NetConnection GetConnection (NetEndPoint ep)
Get the connection, if any, for a certain remote endpoint.
void Introduce (NetEndPoint hostInternal, NetEndPoint hostExternal, NetEndPoint clientInternal, NetEndPoint clientExternal, string token)
Send NetIntroduction to hostExternal and clientExternal; introducing client to host.
NetPeer (NetPeerConfiguration config)
NetPeer constructor.
void RawSend (byte[] arr, int offset, int length, NetEndPoint destination)
Send raw bytes; only used for debugging.
NetIncomingMessage ReadMessage ()
Read a pending message from any connection, if any.
bool ReadMessage (out NetIncomingMessage message)
Reads a pending message from any connection, if any. Returns true if message was read, otherwise false.
int ReadMessages (IList< NetIncomingMessage > addTo)
Read a pending message from any connection, if any.
void Recycle (NetIncomingMessage msg)
Recycles a NetIncomingMessage instance for reuse; taking pressure off the garbage collector.
void Recycle (IEnumerable< NetIncomingMessage > toRecycle)
Recycles a list of NetIncomingMessage instances for reuse; taking pressure off the garbage collector.
void RegisterReceivedCallback (SendOrPostCallback callback, SynchronizationContext syncContext=null)
Call this to register a callback for when a new message arrives.
void SendDiscoveryResponse (NetOutgoingMessage msg, NetEndPoint recipient)
Send a discovery response message.
NetSendResult SendMessage (NetOutgoingMessage msg, NetConnection recipient, NetDeliveryMethod method)
Send a message to a specific connection.
NetSendResult SendMessage (NetOutgoingMessage msg, NetConnection recipient, NetDeliveryMethod method, int sequenceChannel)
Send a message to a specific connection.
void SendMessage (NetOutgoingMessage msg, IList< NetConnection > recipients, NetDeliveryMethod method, int sequenceChannel)
Send a message to a list of connections.
void SendUnconnectedMessage (NetOutgoingMessage msg, string host, int port)
Send a message to an unconnected host.
void SendUnconnectedMessage (NetOutgoingMessage msg, NetEndPoint recipient)
Send a message to an unconnected host.
void SendUnconnectedMessage (NetOutgoingMessage msg, IList< NetEndPoint > recipients)
Send a message to an unconnected host.
void SendUnconnectedToSelf (NetOutgoingMessage om)
Send a message to this exact same netpeer (loopback)
void Shutdown (string bye)
Disconnects all active connections and closes the socket.
void Start ()
Binds to socket and spawns the networking thread.
void UnregisterReceivedCallback (SendOrPostCallback callback)
Call this to unregister a callback, but remember to do it in the same synchronization context!
NetIncomingMessage WaitMessage (int maxMillis)
Read a pending message from any connection, blocking up to maxMillis if needed.

Public Properties Documentation

property Configuration

NetPeerConfiguration Lidgren.Network.NetPeer.Configuration;

property Connections

List<NetConnection> Lidgren.Network.NetPeer.Connections;

property ConnectionsCount

int Lidgren.Network.NetPeer.ConnectionsCount;

property MessageReceivedEvent

AutoResetEvent Lidgren.Network.NetPeer.MessageReceivedEvent;

property Port

int Lidgren.Network.NetPeer.Port;

property Socket

Socket Lidgren.Network.NetPeer.Socket;

property Statistics

NetPeerStatistics Lidgren.Network.NetPeer.Statistics;

property Status

NetPeerStatus Lidgren.Network.NetPeer.Status;

property Tag

object Lidgren.Network.NetPeer.Tag;

property UPnP

NetUPnP Lidgren.Network.NetPeer.UPnP;

property UniqueIdentifier

long Lidgren.Network.NetPeer.UniqueIdentifier;

Public Functions Documentation

function Connect [1/4]

inline NetConnection Lidgren::Network::NetPeer::Connect (
    string host,
    int port
) 

function Connect [2/4]

inline NetConnection Lidgren::Network::NetPeer::Connect (
    string host,
    int port,
    NetOutgoingMessage hailMessage
) 

function Connect [3/4]

inline NetConnection Lidgren::Network::NetPeer::Connect (
    NetEndPoint remoteEndPoint
) 

function Connect [4/4]

inline virtual NetConnection Lidgren::Network::NetPeer::Connect (
    NetEndPoint remoteEndPoint,
    NetOutgoingMessage hailMessage
) 

function CreateMessage [1/3]

inline NetOutgoingMessage Lidgren::Network::NetPeer::CreateMessage () 

function CreateMessage [2/3]

inline NetOutgoingMessage Lidgren::Network::NetPeer::CreateMessage (
    string content
) 

function CreateMessage [3/3]

Creates a new message for sending.

inline NetOutgoingMessage Lidgren::Network::NetPeer::CreateMessage (
    int initialCapacity
) 

Parameters:

  • initialCapacity initial capacity in bytes

function DiscoverKnownPeer [1/2]

inline bool Lidgren::Network::NetPeer::DiscoverKnownPeer (
    string host,
    int serverPort
) 

function DiscoverKnownPeer [2/2]

inline void Lidgren::Network::NetPeer::DiscoverKnownPeer (
    NetEndPoint endPoint
) 

function DiscoverLocalPeers

inline void Lidgren::Network::NetPeer::DiscoverLocalPeers (
    int serverPort
) 

function FlushSendQueue

inline void Lidgren::Network::NetPeer::FlushSendQueue () 

function GetConnection

inline NetConnection Lidgren::Network::NetPeer::GetConnection (
    NetEndPoint ep
) 

function Introduce

inline void Lidgren::Network::NetPeer::Introduce (
    NetEndPoint hostInternal,
    NetEndPoint hostExternal,
    NetEndPoint clientInternal,
    NetEndPoint clientExternal,
    string token
) 

function NetPeer

inline Lidgren::Network::NetPeer::NetPeer (
    NetPeerConfiguration config
) 

function RawSend

inline void Lidgren::Network::NetPeer::RawSend (
    byte[] arr,
    int offset,
    int length,
    NetEndPoint destination
) 

function ReadMessage [1/2]

inline NetIncomingMessage Lidgren::Network::NetPeer::ReadMessage () 

function ReadMessage [2/2]

Reads a pending message from any connection, if any. Returns true if message was read, otherwise false.

inline bool Lidgren::Network::NetPeer::ReadMessage (
    out NetIncomingMessage message
) 

Returns:

True, if message was read.

function ReadMessages

inline int Lidgren::Network::NetPeer::ReadMessages (
    IList< NetIncomingMessage > addTo
) 

function Recycle [1/4]

inline void Lidgren::Network::NetPeer::Recycle (
    NetIncomingMessage msg
) 

function Recycle [2/4]

inline void Lidgren::Network::NetPeer::Recycle (
    IEnumerable< NetIncomingMessage > toRecycle
) 

function RegisterReceivedCallback

inline void Lidgren::Network::NetPeer::RegisterReceivedCallback (
    SendOrPostCallback callback,
    SynchronizationContext syncContext=null
) 

function SendDiscoveryResponse

inline void Lidgren::Network::NetPeer::SendDiscoveryResponse (
    NetOutgoingMessage msg,
    NetEndPoint recipient
) 

function SendMessage [1/3]

Send a message to a specific connection.

inline NetSendResult Lidgren::Network::NetPeer::SendMessage (
    NetOutgoingMessage msg,
    NetConnection recipient,
    NetDeliveryMethod method
) 

Parameters:

  • msg The message to send
  • recipient The recipient connection
  • method How to deliver the message

function SendMessage [2/3]

Send a message to a specific connection.

inline NetSendResult Lidgren::Network::NetPeer::SendMessage (
    NetOutgoingMessage msg,
    NetConnection recipient,
    NetDeliveryMethod method,
    int sequenceChannel
) 

Parameters:

  • msg The message to send
  • recipient The recipient connection
  • method How to deliver the message
  • sequenceChannel Sequence channel within the delivery method

function SendMessage [3/3]

Send a message to a list of connections.

inline void Lidgren::Network::NetPeer::SendMessage (
    NetOutgoingMessage msg,
    IList< NetConnection > recipients,
    NetDeliveryMethod method,
    int sequenceChannel
) 

Parameters:

  • msg The message to send
  • recipients The list of recipients to send to
  • method How to deliver the message
  • sequenceChannel Sequence channel within the delivery method

function SendUnconnectedMessage [1/3]

inline void Lidgren::Network::NetPeer::SendUnconnectedMessage (
    NetOutgoingMessage msg,
    string host,
    int port
) 

function SendUnconnectedMessage [2/3]

inline void Lidgren::Network::NetPeer::SendUnconnectedMessage (
    NetOutgoingMessage msg,
    NetEndPoint recipient
) 

function SendUnconnectedMessage [3/3]

inline void Lidgren::Network::NetPeer::SendUnconnectedMessage (
    NetOutgoingMessage msg,
    IList< NetEndPoint > recipients
) 

function SendUnconnectedToSelf

inline void Lidgren::Network::NetPeer::SendUnconnectedToSelf (
    NetOutgoingMessage om
) 

function Shutdown

inline void Lidgren::Network::NetPeer::Shutdown (
    string bye
) 

function Start

inline void Lidgren::Network::NetPeer::Start () 

function UnregisterReceivedCallback

inline void Lidgren::Network::NetPeer::UnregisterReceivedCallback (
    SendOrPostCallback callback
) 

function WaitMessage

inline NetIncomingMessage Lidgren::Network::NetPeer::WaitMessage (
    int maxMillis
) 

The documentation for this class was generated from the following file api/unity-plugin/Scripts/Networking/Lidgren.Network/NetNatIntroduction.cs