/// <summary> /// 处理服务器数据转发 /// </summary> private void WorkingServerSend() { while (true) { string test = "1234"; //listener.SendToClient(Encoding.UTF8.GetBytes(test)); if (gatewayMessagePool.Count > 0) { IGatewayMessage message = gatewayMessagePool.Dequeue(); switch (message.GatewayMessageType) { case (int)GatewayCommand.CLIENT_INFO_QUEST: GatewayPacketMessage gatewaymessage = (GatewayPacketMessage)message; if (gatewaymessage.pHeader.qdLinkCount > 0) { for (int i = 0; i < gatewaymessage.pBody.qclinkNo.Count; i++) { listener.SendToClient(gatewaymessage.pBody.qclinkNo[i], message.GetMessage()); } } else { listener.SendToClient(message.GetMessage()); } break; case (int)GatewayCommand.SERVER_BEATHEART_QUEST: Listener.SetServerHeart(message.LinkNo); Listener.SendToServer( GatewayPacketMessage.CreateServerMessage( message.ClientPacketType, message.LinkNo, message.RemoteEP.ToString(), GatewayCommand.SERVER_BEATHEART_ANSWER, message.GetMessage())); break; case (int)GatewayCommand.SERVER_LOGIN_QUEST: Listener.SetServerHeart(message.LinkNo); Listener.SendToServer( GatewayPacketMessage.CreateServerMessage( message.ClientPacketType, message.LinkNo, message.RemoteEP.ToString(), GatewayCommand.SERVER_LOGIN_ANSWER, message.GetMessage())); break; default: break; } } } }
private void HandlerServer(MessageReceivedEventArgs args) { try { IGatewayMessage message = GatewayPacketMessage.GetMessage(args); lock (gatewayMessagePool) { gatewayMessagePool.Enqueue(message); } } catch { Listener.CloseLink(args.LinqNo); } }
private void WorkingClientSend() { while (true) { if (clientMessagePool.Count > 0) { IClientMessage message = clientMessagePool.Dequeue(); Listener.SendToServer( GatewayPacketMessage.CreateServerMessage( message.ClientPacketType, message.LinkNo, message.RemoteEP.ToString(), GatewayCommand.CLIENT_INFO_QUEST, message.GetMessage())); } } }