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(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 { }
}
}
更多精彩
赞助商链接