public void SendTcp <T>(MessageID messageId, T t) { if (mClient != null) { byte[] data = JsonSerializerUtil.ToJsonByte <T>(t); //ProtoTransfer.SerializeProtoBuf<T>(t); MessageBuffer message = new MessageBuffer((int)messageId, data, mClient.id); mClient.SendTcp(message); } }
private void OnAccept(Session c) { GM_Accept sendData = new GM_Accept(); sendData.conv = c.id; byte[] data = JsonSerializerUtil.ToJsonByte(sendData); MessageBuffer message = new MessageBuffer((int)MessageID.GM_ACCEPT_SC, data, c.id); c.SendTcp(message); }
///// <summary> ///// 通过UDP发送 ///// </summary> ///// <typeparam name="T"></typeparam> ///// <param name="messageId"></param> ///// <param name="data"></param> //public void SendUdp<T>(ClientID clientID, MessageID id, T data) where T : class, ProtoBuf.IExtensible //{ // var client = GetClient(clientID); // if(client== null) // { // return; // } // byte[] bytes = ProtoTransfer.SerializeProtoBuf<T>(data); // MessageBuffer buffer = new MessageBuffer((int)id, bytes, client.acceptSock); // client.SendUdp(buffer); //} /// <summary> /// 通过TCP协议发送 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="messageId"></param> /// <param name="data"></param> public void SendTcp <T>(ClientID clientID, MessageID id, T data) where T : class, ProtoBuf.IExtensible { var client = GetClient(clientID); if (client == null) { return; } //byte[] bytes = ProtoTransfer.SerializeProtoBuf<T>(data); byte[] bytes = JsonSerializerUtil.ToJsonByte <T>(data); MessageBuffer buffer = new MessageBuffer((int)id, bytes, client.acceptSock); client.SendTcp(buffer); }
public void Set <T>(CommandID type, T t) where T : class, ProtoBuf.IExtensible { mType = (int)type; mData = JsonSerializerUtil.ToJsonByte <T>(t); //ProtoTransfer.SerializeProtoBuf<T>(t); }