private static void Send <T>(object data, int protocId, Action <T> callback) { string dataJson = string.Empty; if (data != null) { dataJson = JsonMapper.ToJson(data); } var package = new NetPackage(); package.MsgId = MsgId; package.ProtocId = protocId; package.Data = dataJson; var bytes = Pack(package); if (callback != null) { AddActionToResponseCallbacksCS(package.MsgId, (res) => { var obj = JsonMapper.ToObject <T>(res); callback(obj); }); } SocketClient.Send(bytes); }
public static void EnqueueBrodcastQueueLUA(NetPackage package) { lock (_syncBrodQueueLUA) { _recvBrodcastQueueLUA.Enqueue(package); } }
public static void EnqueueResponseQueueLUA(NetPackage package) { lock (_syncResQueueLUA) { _recvResponseQueueLUA.Enqueue(package); } }
private static NetPackage Unpack(byte[] bytes, out int statusCode) { int pos = 0; int bytesLen = GetInt(bytes, ref pos); if (bytesLen != bytes.Length) { if (IsGzip(bytes)) { bytes = Decompression(bytes); } else { throw new Exception("Package is not full!"); } } statusCode = GetInt(bytes, ref pos); var package = new NetPackage(); package.MsgId = GetInt(bytes, ref pos); var Description = GetString(bytes, ref pos); package.ProtocId = GetInt(bytes, ref pos); var StrTime = GetString(bytes, ref pos); package.Type = GetString(bytes, ref pos); package.Version = GetString(bytes, ref pos); package.Data = GetString(bytes, ref pos); return(package); }
private static void DealBrodcast(NetPackage package) { if (package.Version == "origin") { EnqueueBrodcastQueueCS(package); } else { EnqueueBrodcastQueueLUA(package); } }
private static void DealResponse(NetPackage package) { if (package.Version == "origin") { EnqueueResponseQueueCS(package); } else { EnqueueResponseQueueLUA(package); } }
public static byte[] Pack(NetPackage package) { var packageStr = string.Format("MsgId={0}&ActionId={1}&Sid={2}&Uid={3}&Data={4}", package.MsgId, package.ProtocId, NetPackage.Sid, package.Uid, package.Data); //Debug.Log("Send:" + packageStr); byte[] tempBytes = Encoding.ASCII.GetBytes(packageStr); byte[] len = BitConverter.GetBytes(tempBytes.Length); byte[] resultBytes = new byte[tempBytes.Length + len.Length]; Buffer.BlockCopy(len, 0, resultBytes, 0, len.Length); Buffer.BlockCopy(tempBytes, 0, resultBytes, len.Length, tempBytes.Length); return(resultBytes); }
private static void Send(object data, int protocId, int msgId) { string dataJson = string.Empty; if (data != null) { dataJson = JsonMapper.ToJson(data); } var package = new NetPackage(); package.MsgId = msgId; package.ProtocId = protocId; package.Data = dataJson; var bytes = Pack(package); SocketClient.Send(bytes); }
private void LogRevPackage(NetPackage package) { var msg = string.Format("{0} Recieve:\nProtocId:{1}\nData:{2}", package.Type, package.ProtocId, package.Data); Debug.Log(msg); }