public bool DoMessage(string key, Protomsg.MsgBase msg) { if (m_Handler.ContainsKey(key)) { return(m_Handler[key](msg)); } return(true); }
public void SendMsg(Protomsg.MsgBase msg) { //UnityEngine.Debug.Log("msg:"+ msg.ToString()); ByteBuf bb = new ByteBuf(msg.ToByteArray()); this.Send(bb); }
/// <summary> /// 超时 /// </summary> protected override void HandleTimeout() { base.HandleTimeout(); UnityEngine.Debug.Log("HandleTimeout"); Protomsg.MsgBase msg = new Protomsg.MsgBase(); msg.MsgType = "TimeOut"; MsgManager.Instance.AddMessage(msg); }
public void SendHeartMsg() { Protomsg.MsgBase msg1 = new Protomsg.MsgBase(); msg1.MsgType = "CS_Heart"; ByteBuf bb = new ByteBuf(msg1.ToByteArray()); //UnityEngine.Debug.Log("SendHeartMsg:"+ Tool.getMemory(this)); this.Send(bb); m_SendHeartTime = Tool.GetTime(); }
public void UpdateMessage() { while (true) { Protomsg.MsgBase msgobj = PopMessage(); if (msgobj == null) { return; } if (DoMessage(msgobj.MsgType, msgobj) == false) { return; } } }
public void SendMsg(String modetype, String msgtype, IMessage msg) { Protomsg.MsgBase msg1 = new Protomsg.MsgBase(); msg1.ModeType = modetype; msg1.MsgType = msgtype; if (msg != null) { msg1.Datas = ByteString.CopyFrom(msg.ToByteArray()); } ByteBuf bb = new ByteBuf(msg1.ToByteArray()); this.Send(bb); }
/// <summary> /// 异常 /// </summary> protected override void HandleException(Exception ex) { base.HandleException(ex); UnityEngine.Debug.Log("-------HandleException" + ex.ToString()); //UnityEngine.Debug.Log("HandleException:" + Tool.getMemory(this)); Protomsg.CC_Disconnect msg = new Protomsg.CC_Disconnect(); msg.Err = ex.ToString(); Protomsg.MsgBase msg1 = new Protomsg.MsgBase(); msg1.ModeType = ""; msg1.MsgType = "CC_Disconnect"; if (msg != null) { msg1.Datas = ByteString.CopyFrom(msg.ToByteArray()); } MsgManager.Instance.AddMessage(msg1); }
protected override void HandleReceive(ByteBuf bb) { IMessage IMperson = new Protomsg.MsgBase(); Protomsg.MsgBase p1 = (Protomsg.MsgBase)IMperson.Descriptor.Parser.ParseFrom(bb.GetRaw()); //UnityEngine.Debug.Log("HandleReceive:" + p1.MsgType); if (p1.MsgType == "SC_Heart") { //this.SendHeartMsg(); var time = Tool.GetTime(); PingValue = (int)Math.Floor((time - m_SendHeartTime) * 1000); //UnityEngine.Debug.Log("ping:"+ PingValue); return; } MsgManager.Instance.AddMessage(p1); // UnityEngine.Debug.Log("MsgType:" + p1.MsgType+ "ModeType:" + p1.ModeType + "ConnectId:" + p1.ConnectId + "Uid:" + p1.Uid); //this.Send(bb.Copy()); }