private IMsgHandler CreateCmdHandler(CmdData cmdData) { IMsgHandler msgHandler = null; switch (cmdData.CmdType) { case CMD_SHUTDOWN: msgHandler = new ShutdownCmd(cmdData.ParamStr); break; case CMD_SCREENLOCK: msgHandler = new ScreenLockCmd(cmdData.ParamStr); break; case CMD_PPT: msgHandler = new PptCmd(cmdData.ParamStr); break; case CMD_MUSIC: msgHandler = new MusicCmd(cmdData.ParamStr); break; case CMD_VOLUME: msgHandler = new VolumeCmd(cmdData.ParamStr); break; } return(msgHandler); }
public void RemoveHandler(IMsgHandler handler) { if (handler != null) { handlers.Remove(handler); } }
void InitOrleans() { try { // Orleans comes with a rich XML and programmatic configuration. Here we're just going to set up with basic programmatic config var config = ClientConfiguration.LocalhostSilo(30000); GrainClient.Initialize(config); if (GrainClient.IsInitialized) { friend = GrainClient.GrainFactory.GetGrain <IMsgHandler>(0); observer = new MsgObserver((msg) => MsgReceiver(msg)); observer = GrainClient.GrainFactory.CreateObjectReference <IMsgObserver>(observer).Result; friend.Subscribe(observer).Wait(); //var friend = GrainClient.GrainFactory.GetGrain<IHello>(0); //var result = friend.SayHello(textBox1.Text).Result; //ClientWrapper = new ConnectorClientWrapper(1,(msg) => { ucLogMessageBox1.PrintShowLogMessage(msg); }); } } catch (Exception ex) { ucLogMessageBox1.PrintShowLogMessage(ex.Message); return; } ucLogMessageBox1.PrintShowLogMessage("客户端初始化成功."); }
public MsgHandlerMgr RegisterHander(IMsgHandler handler) { if (handler != null) { handlers.Add(handler); } return(this); }
// GET api/<controller> public MessageController(IMsgHandler handler) { _handler = handler; if (temps == null) { temps = new Dictionary <int, string>(); } uptime = DateTime.Now; }
// GET api/<controller> public MessageController(IMsgHandler handler) { _handler = handler; if (temps == null) { temps = new Dictionary<int, string>(); } uptime = DateTime.Now; }
private async void button1_Click(object sender, EventArgs e) { friend = GrainClient.GrainFactory.GetGrain <IMsgHandler>(0); await friend.SendMsg(textBox1.Text.Trim()); //ClientWrapper.PublishMessage(textBox1.Text).Wait(); //var friend = GrainClient.GrainFactory.GetGrain<IHello>(0); //var result = friend.SayHello(textBox1.Text).Result; //ucLogMessageBox1.PrintShowLogMessage(result); //friend.SendUpdateMessage(textBox1.Text); }
/// <summary> /// 检测处理器链表中是否已经存在相同的处理器 /// </summary> protected bool ExistHandler(HandlerLink link, IMsgHandler msgHandler) { while (link != null) { if (link.Handler == msgHandler) { return(true); } link = link.Next; } return(false); }
public override void Handle(TransactionController controller, object state) { try { IMsgHandler msgHandler = CreateCmdHandler( StrUtil.JsonToObject <CmdData>(dataStr)); msgHandler.Handle(controller, state); } catch (Exception e) { Logging.Error(e); } }
//public bool HasRecvEvent //{ // get { return hasRecvEvent; } // set { hasRecvEvent = value; } //} public static void RegisterHandler(Protocol p, IMsgHandler h) { lock ( handlers){ if (handlers.ContainsKey(p)) { if (h != null) { handlers[p] = h; } } else { handlers.Add(p, h); } } }
private void ReceiveData(WebSocket sender, MessageEventArgs e) { DataVO vo = JsonUtility.FromJson <DataVO>(e.Data); IMsgHandler handler = handlerDictionary[vo.type]; handler.HandleMsg(vo.payload); //굳이 리플렉션 안써도 딕셔너리로 충분히 해결가능 // MethodInfo m = this.GetType().GetMethod($"{vo.type}Handler", BindingFlags.Instance | BindingFlags.NonPublic); // if(m == null){ // Debug.Log("에러 발생 정의되지 않은 타입"); // } // m.Invoke(this, new object[]{vo.payload}); }
/// <summary> /// 取消指定消息处理器的注册 /// </summary> /// <param name="msgHandler">要取消注册的消息处理器</param> public void UnRegister(IMsgHandler msgHandler) { if (msgHandler == null) { return; } int[] keys = msgHandler.MsgIds; if (keys != null && keys.Length > 0) { foreach (int key in keys) { if (MsgHandlerMap.ContainsKey(key)) { HandlerLink link = MsgHandlerMap [key] as HandlerLink; HandlerLink up = null; while (link != null) { if (link.Handler == msgHandler) { link.Handler = null; if (up != null) { up.Next = link.Next; } else if (link.Next == null) { MsgHandlerMap.Remove(key); } else { MsgHandlerMap [key] = link.Next; } break; } else { up = link; link = link.Next; } } } } } }
//接收TCPServer信息字符串 public static void RecvTCPDatagram(object sender, NetEventArgs e) { String msg1 = e.Client.Datagram; //HERRYConsole.WriteLine(msg1); string[] sResult = DataSplit(e.Client.Datagram); if (sResult != null && sResult.Length > 2) { Console.WriteLine(" TTTTTTTTT " + sResult[1]); Protocol p = AppUtil.ParseProtocol(sResult[1]); if (p != Protocol.UNKNOWN) { Console.WriteLine(" Protocol @@@@@@@@@@@@@@@@ " + p); LogUtil.Info("Protocol : " + p + " Msg content " + msg1); IMsgHandler handler = GetHandler(p); if (handler != null) { handler.Receive(sResult); } } } }
/// <summary> /// 注册消息处理服务 /// </summary> /// <param name="msgHandler">消息处理器对象</param> public void Register(IMsgHandler msgHandler, int msgID) { if (msgHandler == null || msgID == 0) { return; } HandlerLink link = GetHandlerLink(msgID); if (link == null) { link = new HandlerLink(); link.Handler = msgHandler; MsgHandlerMap.Add(msgID, link); } else if (!ExistHandler(link, msgHandler)) { while (link.Next != null) { link = link.Next; } link.Next = new HandlerLink(); link.Next.Handler = msgHandler; } }
public static IMsgHandler CreateMsgHandler(MsgPacket packet) { IMsgHandler msgHandler = null; switch (packet.TypeStr) { case MsgPacket.TYPE_IP: msgHandler = new IPMsgHandler(packet.DataStr); break; case MsgPacket.TYPE_CMD: msgHandler = new CmdMsgHandler(packet.DataStr); break; case MsgPacket.TYPE_ANS: msgHandler = new AnsMsgHandler(packet.DataStr); break; case MsgPacket.TYPE_GUN: msgHandler = new GunMsgHandler(packet.DataStr); break; } return(msgHandler); }
void OnDestroy() { if (null != m_MessageEventHandler) { m_MessageEventHandler.Dispose(); m_MessageEventHandler = null; } Disconnect(); foreach (ISocketClient socket in m_SocketList) { socket.Close(); } m_SocketList.Clear(); if (null != m_oSendRecycle) { m_oSendRecycle.Release(); m_oSendRecycle = null; } if (null != m_oRecieveRecycle) { m_oRecieveRecycle.Release(); m_oRecieveRecycle = null; } if (null != m_oRecieveQueue) { m_oRecieveQueue.Release(); m_oRecieveQueue = null; } }
private void OnReceive(Gamnet.Buffer buf) { _recv_buff += buf; while (_recv_buff.Size() >= Packet.HEADER_SIZE) { ushort packetLength = BitConverter.ToUInt16(_recv_buff.data, _recv_buff.read_index + Packet.OFFSET_LENGTH); uint msgID = BitConverter.ToUInt32(_recv_buff.data, _recv_buff.read_index + Packet.OFFSET_MSGID); uint msgSEQ = BitConverter.ToUInt32(_recv_buff.data, _recv_buff.read_index + Packet.OFFSET_MSGSEQ); bool reliable = BitConverter.ToBoolean(_recv_buff.data, _recv_buff.read_index + Packet.OFFSET_RELIABLE); if (packetLength > Gamnet.Buffer.BUFFER_SIZE) { Debug.LogError("[Session.OnReceive] The packet length is greater than the buffer max length."); Error(new Gamnet.Exception(ErrorCode.UndefinedError, "The packet length is greater than the buffer max length.")); return; } if (packetLength > _recv_buff.Size()) { // not enough return; } _recv_buff.read_index += Packet.HEADER_SIZE; _timeout_monitor.UnsetTimeout(msgID); try { if (false == _handlers.ContainsKey(msgID)) { Debug.LogWarning("[Session.OnReceive] can't find registered msg(id:" + msgID + ")"); throw new Gamnet.Exception(ErrorCode.UnhandledMsgError, "can't find registered msg(id:" + msgID + ")"); } if (false == reliable || _recv_seq < msgSEQ) { System.IO.MemoryStream ms = new System.IO.MemoryStream(); ms.Write(_recv_buff.data, _recv_buff.read_index, packetLength - Packet.HEADER_SIZE); ms.Seek(0, System.IO.SeekOrigin.Begin); IMsgHandler handler = _handlers[msgID]; handler.OnRecvMsg(ms); _recv_seq = Math.Max(_recv_seq, msgSEQ); if (true == reliable) { Send_ReliableAck_Ntf(_recv_seq); } } } catch (Gamnet.Exception e) { Debug.LogError("[Session.OnReceive] " + e.ToString()); Error(e); } catch (System.Exception e) { Debug.LogError("[Session.OnReceive] " + e.ToString()); Error(new Gamnet.Exception(ErrorCode.UndefinedError, e.ToString())); } _recv_buff.read_index += packetLength - Packet.HEADER_SIZE; } }
public bool AddRequestHandler(IMsgHandler requestHandler) { m_RequestHandlers.Add(requestHandler); return requestHandler != null; }
private async void button1_Click(object sender, EventArgs e) { friend = GrainClient.GrainFactory.GetGrain <IMsgHandler>(0); await friend.SendMsg(textBox1.Text.Trim()); }
//public bool HasRecvEvent //{ // get { return hasRecvEvent; } // set { hasRecvEvent = value; } //} public static void RegisterHandler( Protocol p, IMsgHandler h) { lock( handlers){ if (handlers.ContainsKey(p)) { if (h != null) { handlers[p] = h; } } else { handlers.Add(p, h); } } }
public void SetMsgHndler(IMsgHandler msgHandler) { mMsgHandler = msgHandler; }
public static void SetMsgHandler(IMsgHandler msghandler) { MsgHandler._msgHandler = msghandler; }
public void RegistMessageFunction(string callback) { m_MessageEventHandler = new LuaMsgHandler(); m_MessageEventHandler.Create(LuaManager.Instance.luaEnv, callback); }
/// <summary> /// 注册消息处理服务 /// </summary> /// <param name="msgHandler">消息处理器对象</param> public void Register(IMsgHandler msgHandler, int msgID) { MsgEngine.Instance.Register(msgHandler, msgID); }