WEB开发网
开发学院软件开发C语言 P2P网络通讯程序(c#) 阅读

P2P网络通讯程序(c#)

 2009-03-27 08:22:11 来源:WEB开发网   
核心提示: 3、服务端a、消息处理线程 private void RecvThreadProc() { IPEndPoint remotePoint = null; byte[] msgBuffer = null; while (true) { msgBuffer = server.Receive(

3、服务端

a、消息处理线程

  private void RecvThreadProc()
        {
            IPEndPoint remotePoint = null;
            byte[] msgBuffer = null;
            while (true)
            {            
                msgBuffer = server.Receive(ref remotePoint);
                try
                {
                    object msgObj = UtilityHelper.Deserialize(msgBuffer);
                    switch ((msgObj as Packet).GetCommandType())
                    {
                        case Command.MSG_USERLOGIN:         //用户登录                           
                            ProcUserLoginMsg(msgObj as UserLoginPacket, remotePoint);
                            break;
                        case Command.MSG_USERLOGOUT:        //退出登录
                            ProcUserLogoutMsg(msgObj as UserLogoutPacket, remotePoint);
                            break;
                        case Command.MSG_GETUSERLIST:       //所有用户列表                           
                            ProcGetUserListMsg(msgObj as UserListPacket, remotePoint);
                            break;
                        case Command.MSG_P2PCONNECT:        //点对点连接信息                          
                            ProcP2PConnectMsg(msgObj as P2PConnectionPacket, remotePoint);
                            break;
                        case Command.MSG_USERACTIVEQUERY:   // 用户对服务器轮询的应答                           
                            ProcUserActiveQueryMsg(msgObj as UserActiveQueryPacket, remotePoint);
                            break;
                    }
                    Thread.Sleep(100);
                }
                catch { }
            }
        }

上一页  1 2 3 4 5 6  下一页

Tags:PP 网络通讯 程序

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接