Пример #1
0
        /// <summary>
        /// 建立连接
        /// </summary>
        /// <param name="dns">对方的IP End Point</param>
        /// <param name="id">对方节点的ID号</param>
        public void StartConnect(IPEndPoint dns, byte[] id)
        {
            //如果本地连接数大于最大连接数,则返回
            if (connections.Count >= maxInitiate)
            {
                return;
            }

            //如果ID号相同,则表明是本地发送的网络信息,则返回
            if (Globals.IsArrayEqual(id, myID, 20))
            {
                return;
            }

            //如果该ID号已经存在,则返回
            foreach (IEncryptedConnection item in connections.Values)
            {
                if (Globals.IsArrayEqual(id, item.ID, 20))
                {
                    return;
                }
            }

            //开始建立连接
            try
            {
                ISingleSocket singleSocket = rawServer.StartConnect(dns, null);
                connections[singleSocket] = new EncryptedConnection(this, singleSocket, id);
            }

            catch
            {
                return;
            }
        }
Пример #2
0
 /// <summary>
 /// 增加连接
 /// </summary>
 /// <param name="singleSocket">待建立的单套接字</param>
 public void MakeExternalConnection(ISingleSocket singleSocket)
 {
     connections[singleSocket] = new EncryptedConnection(this, singleSocket, null);
 }