/// <summary> /// Create a connection to a remote endpoint /// </summary> public virtual NetConnection Connect(NetEndPoint remoteEndPoint, NetOutgoingMessage hailMessage) { if (remoteEndPoint == null) { throw new ArgumentNullException("remoteEndPoint"); } lock (m_connections) { if (m_status == NetPeerStatus.NotRunning) { throw new NetException("Must call Start() first"); } // make unique connection id var connectionId = NetUtility.MakeConnectionId(); while (m_handshakes.ContainsKey(connectionId)) { connectionId = NetUtility.MakeConnectionId(); } NetConnection conn = new NetConnection(this, remoteEndPoint, connectionId); conn.m_status = NetConnectionStatus.InitiatedConnect; conn.m_localHailMessage = hailMessage; // handle on network thread conn.m_connectRequested = true; conn.m_connectionInitiator = true; m_handshakes.Add(conn.m_connectionId, conn); return(conn); } }