public bool Reply(BroadcastEventArgs arg, List <KellPersistence.Data <ClonableObject> > msgs) { if (true)//待完善... { foreach (KellPersistence.Data <ClonableObject> msg in msgs) { trunk.Delete(msg.ID); } return(true); } return(false); }
static void BroadcastEvent_Received(object sender, BroadcastEventArgs arg) { if (Received != null) { Received(arg.Client, arg.Data); } if (arg.Data != null) { ClonableObject msg = Common.GetMsgClonable <ClonableObject>(arg.Data); if (msg != null) { ev.Enqueue(msg); Console.WriteLine("接收到来自客户端[" + arg.Client + "]的订阅型消息:" + msg.GetHashCode() + ",并插入队列成功!"); } else { string clientId = Common.GetString(arg.Data, 0, Encoding.UTF8); if (clientId != null) { Console.WriteLine("接收到客户端[" + clientId + "]的订阅型消息的订阅请求!"); } } } }
/// <summary> /// 发送广播 /// </summary> /// <param name="arg"></param> public void Broadcast(BroadcastEventArgs arg) { if (Broadcasting != null) { EventHandler <BroadcastEventArgs> tmpEvent = null; IEnumerator enumerator = Broadcasting.GetInvocationList().GetEnumerator(); while (enumerator.MoveNext()) { Delegate handler = (Delegate)enumerator.Current; try { tmpEvent = (EventHandler <BroadcastEventArgs>)handler; arg.Channel = this.channel; tmpEvent(this, arg); } catch (Exception e) { Logs.Create("触发Broadcast时出错:" + e.Message);//错误信息:在分析完成之前就遇到流结尾。 //注册的事件处理程序出错,删除 Broadcasting -= tmpEvent; } } } }