You've already forked lidgren-network-gen3
mirror of
https://github.com/lidgren/lidgren-network-gen3.git
synced 2026-05-18 08:06:33 +09:00
TryConnect() added
This commit is contained in:
@@ -184,10 +184,31 @@ namespace Lidgren.Network
|
||||
return Connect(new IPEndPoint(NetUtility.Resolve(host), port), approvalMessage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to create a connection to a remote endpoint; returns true on success
|
||||
/// Note that the connection attempt may still fail; the returning value only indicates that the connection procedure initiated successfully
|
||||
/// </summary>
|
||||
public bool TryConnect(IPEndPoint remoteEndpoint, NetOutgoingMessage approvalMessage, out NetConnection connection)
|
||||
{
|
||||
lock (m_connections)
|
||||
{
|
||||
if (m_status == NetPeerStatus.NotRunning || m_connectionLookup.ContainsKey(remoteEndpoint))
|
||||
{
|
||||
connection = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
connection = Connect(remoteEndpoint, approvalMessage);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a connection to a remote endpoint
|
||||
/// </summary>
|
||||
public virtual NetConnection Connect(IPEndPoint remoteEndpoint, NetOutgoingMessage approvalMessage)
|
||||
public NetConnection Connect(IPEndPoint remoteEndpoint, NetOutgoingMessage approvalMessage)
|
||||
{
|
||||
lock (m_connections)
|
||||
{
|
||||
if (m_status == NetPeerStatus.NotRunning)
|
||||
throw new NetException("Must call Start() first");
|
||||
@@ -202,14 +223,12 @@ namespace Lidgren.Network
|
||||
conn.m_connectRequested = true;
|
||||
conn.m_connectionInitiator = true;
|
||||
|
||||
lock (m_connections)
|
||||
{
|
||||
m_connections.Add(conn);
|
||||
m_connectionLookup[remoteEndpoint] = conn;
|
||||
}
|
||||
|
||||
return conn;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send a message to an existing connection
|
||||
|
||||
Reference in New Issue
Block a user