public void Request <T>(string name, T body) where T : IMessageLite { MessageHeaderRequest.Builder header = MessageHeaderRequest.CreateBuilder(); header.SetName(name); byte[] headerBytes = header.Build().ToByteArray(); byte[] bodyBytes = body.ToByteArray(); SendRequest(headerBytes, bodyBytes); }
/// <summary> /// 发送心跳包 /// </summary> /// <returns></returns> private IEnumerator StartHeartBeat() { while (m_HeartBeat) { MessageHeaderRequest.Builder header = MessageHeaderRequest.CreateBuilder(); header.SetName("Heart"); byte[] headerBytes = header.Build().ToByteArray(); List <byte[]> buffs = new List <byte[]>(); buffs.Add(NetworkProtoParser.SizeToVariant32(headerBytes)); buffs.Add(headerBytes); buffs.Add(new byte[1] { 0 }); foreach (byte[] buff in buffs) { m_socket.Send(buff); } yield return(null); } }
public void Request(string name, byte[] body, DelegateRPC callback) { m_callback = callback; MessageHeaderRequest.Builder header = MessageHeaderRequest.CreateBuilder(); header.SetName(name); MessageHeaderInfo.Builder messageHeaderInfo = MessageHeaderInfo.CreateBuilder(); messageHeaderInfo.SetUserToken(m_token); if (m_sign != null) { messageHeaderInfo.SetSign(m_sign); } if (m_userId != -1) { messageHeaderInfo.SetUserId(m_userId); } header.SetUserInfo(messageHeaderInfo); byte[] headerBytes = header.Build().ToByteArray(); SendRequest(headerBytes, body); }