You've already forked lidgren-network-gen3
mirror of
https://github.com/lidgren/lidgren-network-gen3.git
synced 2026-05-17 23:56:30 +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);
|
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>
|
/// <summary>
|
||||||
/// Create a connection to a remote endpoint
|
/// Create a connection to a remote endpoint
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual NetConnection Connect(IPEndPoint remoteEndpoint, NetOutgoingMessage approvalMessage)
|
public NetConnection Connect(IPEndPoint remoteEndpoint, NetOutgoingMessage approvalMessage)
|
||||||
|
{
|
||||||
|
lock (m_connections)
|
||||||
{
|
{
|
||||||
if (m_status == NetPeerStatus.NotRunning)
|
if (m_status == NetPeerStatus.NotRunning)
|
||||||
throw new NetException("Must call Start() first");
|
throw new NetException("Must call Start() first");
|
||||||
@@ -202,14 +223,12 @@ namespace Lidgren.Network
|
|||||||
conn.m_connectRequested = true;
|
conn.m_connectRequested = true;
|
||||||
conn.m_connectionInitiator = true;
|
conn.m_connectionInitiator = true;
|
||||||
|
|
||||||
lock (m_connections)
|
|
||||||
{
|
|
||||||
m_connections.Add(conn);
|
m_connections.Add(conn);
|
||||||
m_connectionLookup[remoteEndpoint] = conn;
|
m_connectionLookup[remoteEndpoint] = conn;
|
||||||
}
|
|
||||||
|
|
||||||
return conn;
|
return conn;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Send a message to an existing connection
|
/// Send a message to an existing connection
|
||||||
|
|||||||
Reference in New Issue
Block a user