/// <summary> /// 发送数据 /// </summary> /// <typeparam name="TRsp"></typeparam> /// <param name="cmd"></param> /// <param name="req"></param> /// <param name="onRsp"></param> /// <param name="timeout"></param> /// <param name="onErr"></param> /// <returns>返回唯一的发送Index</returns> public uint Send <TRsp>(uint cmd, object req, Action <uint, TRsp> onRsp, float timeout = 30, Action <NetErrorCode> onErr = null) { Debuger.LogVerbose("cmd:{0}, timeout:{1}", cmd, timeout); uint index = MessageIndexGenerator.NewIndex(); ListenerHelper helper = new ListenerHelper() { cmd = cmd, index = index, TMsg = typeof(TRsp), onErr = onErr, onMsg0 = onRsp, timeout = timeout, timestamp = SGFTime.GetTimeSinceStartup() }; m_listRspListener.Add(index, helper); NetMessage msg = new NetMessage(); msg.head.index = index; msg.head.cmd = cmd; msg.head.token = m_token; msg.content = PBSerializer.NSerialize(req); msg.head.dataSize = (uint)msg.content.Length; m_conn.Send(msg); return(index); }
public void Send <TReq, TRsp>(uint cmd, TReq req, Action <TRsp> onRsp, float timeout = 30, Action <NetErrorCode> onErr = null) { NetMessage msg = new NetMessage(); msg.head.index = MessageIndexGenerator.NewIndex(); msg.head.cmd = cmd; msg.head.uid = m_uid; msg.Pack(req, m_SendBuff); m_conn.Send(m_SendBuff.GetBuffer(), (int)m_SendBuff.Size); AddListener(cmd, typeof(TRsp), onRsp, msg.head.index, timeout, onErr); }
public void Send <TReq, TRsp>(uint cmd, TReq req, Action <TRsp> onRsp, float timeout = 30, Action <NetErrorCode> onErr = null) { NetMessage msg = new NetMessage(); msg.head.index = MessageIndexGenerator.NewIndex(); msg.head.cmd = cmd; msg.head.uid = m_uid; msg.content = PBSerializer.NSerialize(req); msg.head.dataSize = (ushort)msg.content.Length; byte[] temp; int len = msg.Serialize(out temp); m_conn.Send(temp, len); AddListener(cmd, typeof(TRsp), onRsp, msg.head.index, timeout, onErr); }