/// <summary> /// 自由线程,检测未发送的数据并发出 /// </summary> void CheckUnConfirmedQueue() { //异步调用委托 if (cucqCallpack == null) { cucqCallpack = (s) => OnPackageSendFailure(s as PackageEventArgs); } if (resendCallback == null) { resendCallback = (s) => OnPackageResend(s as PackageEventArgs); } do { if (SendList.Count > 0) { PacketNetWorkMsg[] array = null; lock (SendList) { array = SendList.ToArray(); } //挨个重新发送并计数 Array.ForEach(array, s => { s.SendTimes++; if (s.SendTimes >= MaxResendTimes) { //发送失败啊 PackageEventArgs e = new PackageEventArgs(); if (SeiClient.NeedPostMessage) { SeiClient.SendSynchronizeMessage(cucqCallpack, e); } else { OnPackageSendFailure(e);//触发发送失败事件 } SendList.Remove(s); } else { //重新发送 AsyncSendPacket(s); PackageEventArgs e = new PackageEventArgs() { PacketMsg = s }; if (SeiClient.NeedPostMessage) { SeiClient.SendASynchronizeMessage(resendCallback, e); } else { OnPackageResend(e);//触发重新发送事件 } } }); } Thread.Sleep(CheckQueueTimeInterval); } while (IsInitialized); }
public Form1() { InitializeComponent(); Config cfg = SeiClient.GetDefaultConfig(); cfg.Port = 7777; UDPThread udp = new UDPThread(cfg); tran = new MsgTranslator(udp, cfg); tran.MessageReceived += tran_MessageReceived; }
/// <summary> /// 触发收到文本消息事件 /// </summary> /// <param name="e">事件参数</param> protected virtual void OnTextMessageReceived(MessageEventArgs e) { if (TextMessageReceived == null) { return; } if (SeiClient.NeedPostMessage) { if (textMessageReceivedCall == null) { textMessageReceivedCall = s => TextMessageReceived(this, s as MessageEventArgs); } SeiClient.SendSynchronizeMessage(textMessageReceivedCall, e); } else { TextMessageReceived(this, e); } }
/// <summary> /// 引发消息已经发送事件 /// </summary> /// <param name="e"></param> protected virtual void OnMessageSended(MessageEventArgs e) { if (MessageSended == null) { return; } if (!SeiClient.NeedPostMessage) { MessageSended(this, e); } else { if (messageSendedCall == null) { messageSendedCall = s => MessageSended(this, s as MessageEventArgs); } SeiClient.SendSynchronizeMessage(messageSendedCall, e); } }