public void SendProtocolBytes(Protocol.PROTOCOL protocol, byte[] strByte) { ByteBuffer b = new ByteBuffer(); b.WriteInt(System.Net.IPAddress.HostToNetworkOrder((int)protocol)); Log("添加消息[ " + protocol.ToString() + " ]进入队列"); if (strByte != null) { int packCount = Mathf.CeilToInt((float)strByte.Length / 117f); List <byte> result = new List <byte>(); for (int i = 0; i < packCount; i++) { int len = (strByte.Length - 117 * i); if (len > 117) { len = 117; } byte[] cutByte = new byte[len]; for (int j = 0; j < len; j++) { cutByte[j] = strByte[i * 117 + j]; } result.AddRange(RSA.Encrypt(cutByte)); } byte[] r = result.ToArray(); b.WriteBytes(r); } outQueue.Enqueue(new KeyValuePair <NetActionType, ByteBuffer>(NetActionType.Message, b)); }
/// <summary> /// 发送协议 /// </summary> /// <param name="protocol"></param> /// <param name="data"></param> /// <param name="callback"></param> public void SendProtocol(Protocol.PROTOCOL protocol, Dictionary <string, object> data, ProtocolCallback callback) { if (callback != null) { AddCallback(callback); } client.SendProtocol(protocol, data); }
public void SendProtocol(Protocol.PROTOCOL protocol, Dictionary <string, object> data) { if (data == null) { SendProtocolBytes(protocol, null); } else { string s = MiniJSON.Json.Serialize(data); Byte[] strByte = System.Text.Encoding.UTF8.GetBytes(s); SendProtocolBytes(protocol, strByte); } }