Exemplo n.º 1
0
        private void SendAck(TcpSocketSaeaSession session, SessionWorkType type)
        {
            //                          //命令头      //accesskey     //workType
            byte[] bytes = new byte[sizeof(Int16) + sizeof(Int64) + sizeof(Byte)];
            BitConverter.GetBytes(AckPacket).CopyTo(bytes, 0);
            BitConverter.GetBytes(_options.AccessKey).CopyTo(bytes, 2);
            bytes[10] = (Byte)type;

            byte[] body = CompressHelper.Compress(bytes, 0, bytes.Length);

            byte[] data = new byte[sizeof(Int32) + body.Length];
            BitConverter.GetBytes(body.Length).CopyTo(data, 0);
            body.CopyTo(data, 4);

            session.SendAsync(data);
        }
        private void SendAck(TcpSocketSaeaSession session, SessionWorkType type)
        {
            var typeByte = (byte)type;
            var ackBody  = SerializePacket(new AckPack()
            {
                Type      = typeByte.ConvertTo <ConnectionWorkType>(),
                AccessId  = _options.AccessId,
                AccessKey = _options.AccessKey
            });

            ackBody = GZipHelper.Compress(ackBody, 0, ackBody.Length);

            var dataBuilder = new List <byte>();

            dataBuilder.AddRange(BitConverter.GetBytes(ackBody.Length));
            dataBuilder.AddRange(ackBody);
            ackBody = dataBuilder.ToArray();
            dataBuilder.Clear();
            session.SendAsync(ackBody);//构造发送
        }