private void DispatchMessage(Message message) { if (message.IsMessage(MessageType.UDPQUERYBAG)) { UDPRevResultMessage revmsg = EntityBufCore.DeSerialize <UDPRevResultMessage>(message.MessageBuffer); var respmsg = new Message(MessageType.UDPANSWERBAG); bool isreved = false; revmsg.Miss = GetMissSegment(revmsg.BagId, null, out isreved); revmsg.IsReved = isreved; respmsg.SetMessageBody(revmsg); SendMessage(respmsg, null); } else if (message.IsMessage(MessageType.UDPANSWERBAG)) { UDPRevResultMessage revmsg = EntityBufCore.DeSerialize <UDPRevResultMessage>(message.MessageBuffer); AutoReSetEventResult wait = null; if (_resetevent.TryGetValue(revmsg.BagId, out wait)) { wait.WaitResult = revmsg; wait.IsTimeOut = false; wait.Set(); } } else { OnMessage(message); } }
private void DispatchMessage(Message message, IPEndPoint endpoint) { if (message.IsMessage(MessageType.UDPQUERYBAG)) { UDPRevResultMessage revmsg = LJC.FrameWork.EntityBuf.EntityBufCore.DeSerialize <UDPRevResultMessage>(message.MessageBuffer); var respmsg = new Message(MessageType.UDPANSWERBAG); bool isreved = false; revmsg.Miss = GetMissSegment(revmsg.BagId, endpoint, out isreved); revmsg.IsReved = isreved; respmsg.SetMessageBody(revmsg); SendMessage(respmsg, endpoint); } else if (message.IsMessage(MessageType.UDPANSWERBAG)) { UDPRevResultMessage revmsg = LJC.FrameWork.EntityBuf.EntityBufCore.DeSerialize <UDPRevResultMessage>(message.MessageBuffer); AutoReSetEventResult wait = null; string key = string.Format("{0}:{1}:{2}", endpoint.Address.ToString(), endpoint.Port, revmsg.BagId); if (_resetevent.TryGetValue(key, out wait)) { wait.WaitResult = revmsg; wait.IsTimeOut = false; wait.Set(); } } else if (message.IsMessage(MessageType.UPDSETMTU)) { var mtu = LJC.FrameWork.EntityBuf.EntityBufCore.DeSerialize <UDPSetMTUMessage>(message.MessageBuffer).MTU; if (mtu < MTU_MIN) { mtu = MTU_MIN; } if (mtu > MTU_MAX) { mtu = MTU_MAX; } lock (_MTUDic) { var key = endpoint.Address.ToString(); if (_MTUDic.ContainsKey(key)) { _MTUDic[key] = mtu; } else { _MTUDic.Add(key, mtu); } } } else if (message.IsMessage(MessageType.UDPCLEARBAGID)) { ClearTempData(endpoint); } else { FromApp(message, endpoint); } }
protected override void FormAppMessage(Message message, Session session) { //base.ReciveMessage(message); byte[] result = DoMessage(message); if (result != null && !string.IsNullOrEmpty(message.MessageHeader.TransactionID)) { if (watingEvents.Count == 0) { return; } AutoReSetEventResult autoEvent = watingEvents.First(p => p.Key == message.MessageHeader.TransactionID).Value; if (autoEvent != null) { autoEvent.WaitResult = result; autoEvent.IsTimeOut = false; autoEvent.Set(); if (OnAppMessage != null) { OnAppMessage(session, message); } return; } } base.FormAppMessage(message, session); }
protected void ReciveMessage(Message message) { if (!string.IsNullOrEmpty(message.MessageHeader.TransactionID)) { AutoReSetEventResult autoEvent = null; Console.WriteLine("收到消息:" + message.MessageHeader.TransactionID); if (watingEvents.TryGetValue(message.MessageHeader.TransactionID, out autoEvent)) { autoEvent.WaitResult = message.MessageBuffer; autoEvent.IsTimeOut = false; autoEvent.Set(); return; } } }
protected override void ReciveMessage(Message message) { //base.ReciveMessage(message); if (!string.IsNullOrEmpty(message.MessageHeader.TransactionID)) { if (watingEvents.Count == 0) { return; } byte[] result = null; Exception innerex = null; try { result = DoMessage(message); } catch (Exception ex) { innerex = ex; } AutoReSetEventResult autoEvent = null; if (watingEvents.TryGetValue(message.MessageHeader.TransactionID, out autoEvent)) { autoEvent.WaitResult = result; autoEvent.IsTimeOut = false; autoEvent.DataException = innerex; autoEvent.Set(); return; } } base.ReciveMessage(message); }