Beispiel #1
0
        //获取所有在线用户的信息
        private void GetP2PInfo()
        {
            IList <UserIDEndPoint> userInfoList = Common.TcpConn.SendReceiveObject <IList <UserIDEndPoint> >("GetP2PInfo", "ResP2pInfo", 5000, "GetP2P");

            foreach (UserIDEndPoint userInfo in userInfoList)
            {
                try
                {
                    if (userInfo.UserID != Common.CurrentUser.ID)
                    {
                        ConnectionInfo connInfo         = new ConnectionInfo(userInfo.IPAddress, userInfo.Port);
                        Connection     newTcpConnection = TCPConnection.GetConnection(connInfo);
                        Common.AddUserConn(userInfo.UserID, newTcpConnection);


                        SetUpP2PContract contract = new SetUpP2PContract();
                        contract.UserID = Common.CurrentUser.ID;
                        //P2p通道打通后,发送一个消息给对方用户,以便于对方用户收到消息后,建立P2P通道
                        newTcpConnection.SendObject("SetupP2PMessage", contract);
                    }
                }
                catch
                {
                }
            }
        }
Beispiel #2
0
 //收到创建P2P通道的消息
 private void IncomingSetupP2PMessage(PacketHeader header, Connection connection, SetUpP2PContract contract)
 {
     //如果还没有P2P通道,则创建之
     if (!Common.ContainsUserConn(contract.UserID))
     {
         Common.AddUserConn(contract.UserID, connection);
     }
 }
Beispiel #3
0
 //收到创建P2P通道的消息
 private void IncomingSetupP2PMessage(PacketHeader header, Connection connection, SetUpP2PContract contract)
 {
     //如果还没有P2P通道,则创建之
     if (!Common.ContainsUserConn(contract.UserID))
     {
         Common.AddUserConn(contract.UserID, connection);
     }
     LogInfo.LogMessage("收到P2P创建连接消息" + "本地端口是:" + connection.ConnectionInfo.LocalEndPoint.Port.ToString(), "P2PInfo");
 }