public UdpSenderWorkMethodParams(Socket socket, IPEndPoint remoteEP, Message message) { _Socket = socket; _RemoteEP = remoteEP; _Message = message; }
private void ProcessMessage(Message message, IPAddress remoteIP) { if (message == null || message.HeaderData == null) { return; } switch (message.HeaderData.MsgDataType) { case EMsgDataType.Signon: { SignonManager.SignonMgr.ProcessSignonMessage(remoteIP, message.HeaderData.IsReply); } break; case EMsgDataType.ReceiveConfirmation: { if ((message is ReceiveConfirmationMessage) == false) { break; } ReceiveConfirmationMessage receiveConfirmationMessage = message as ReceiveConfirmationMessage; if (receiveConfirmationMessage == null) { break; } if (ReceivedConfirmationList == null) { ReceivedConfirmationList = new List<int>(); } lock (ReceivedConfirmationList) { ReceivedConfirmationList.Add(receiveConfirmationMessage.ReceiveConfirmRefNo); } } break; case EMsgDataType.UserInfo: { if ((message is UserInfoMessage) == false || remoteIP == IPAddress.None) { break; } UserInfoMessage userInfoMessage = message as UserInfoMessage; if (userInfoMessage == null || userInfoMessage.UserInfo == null) { break; } userInfoMessage.UserInfo._IPAddress = remoteIP.ToString(); SignonManager.SignonMgr.ProcessUserInfoMessage(userInfoMessage.UserInfo, remoteIP, message.HeaderData.IsReply); } break; case EMsgDataType.Text: { if ((message is TextMessage) == false || remoteIP == IPAddress.None) { break; } TextMessage textMessage = message as TextMessage; if (textMessage == null) { break; } textMessage.TextMessageData._IPAddress = remoteIP.ToString(); textMessage.TextMessageData._ReceiptTime = DateTime.Now; ProcessTextMessage(textMessage.TextMessageData); } break; } }
private void SendMessage(Socket socket, IPEndPoint remoteEP, Message message) { ParameterizedThreadStart udpListenerThreadStart = new ParameterizedThreadStart(UdpSenderWorkMethod); UdpSenderThread = new Thread(udpListenerThreadStart); UdpSenderThread.IsBackground = true; UdpSenderThread.Name = "UdpSenderThread"; UdpSenderThread.Priority = ThreadPriority.Normal; UdpSenderWorkMethodParams udpSenderWorkMethodParams = new UdpSenderWorkMethodParams(socket, remoteEP, message); UdpSenderThread.Start(udpSenderWorkMethodParams); }
private byte[] ConvertMessageToBytes(Message message) { byte[] data = null; MemoryStream memStream = new MemoryStream(); BinaryFormatter binaryFormatter = new BinaryFormatter(); try { binaryFormatter.Serialize(memStream, message); data = memStream.ToArray(); } catch (Exception ex) { Console.WriteLine(ex.Message); } return data; }