Esempio n. 1
0
        public void Send(byte flag, ushort opcode, byte[] bytes)
        {
            if (this.IsDisposed)
            {
                throw new Exception("session已经被Dispose了");
            }

            this.byteses[0][0] = flag;
            this.byteses[1]    = BytesHelper.GetBytes(opcode);
            this.byteses[2]    = bytes;

#if SERVER
            // 如果是allserver,内部消息不走网络,直接转给session,方便调试时看到整体堆栈
            if (this.Network.AppType == AppType.AllServer)
            {
                Session session = this.Network.Entity.GetComponent <NetInnerComponent>().Get(this.RemoteAddress);
                this.pkt.Length = 0;
                ushort index = 0;
                foreach (var byts in byteses)
                {
                    Array.Copy(byts, 0, this.pkt.Bytes, index, byts.Length);
                    index += (ushort)byts.Length;
                }

                this.pkt.Length = index;
                session.Run(this.pkt);
                return;
            }
#endif

            channel.Send(this.byteses);
        }
Esempio n. 2
0
 public override void Send(byte[] buffer, int index, int length)
 {
     if (this.IsDisposed)
     {
         throw new Exception("TChannel已经被Dispose, 不能发送消息");
     }
     byte[] size = BytesHelper.GetBytes((ushort)buffer.Length);
     this.sendBuffer.Write(size, 0, size.Length);
     this.sendBuffer.Write(buffer, index, length);
     if (this.isConnected)
     {
         this.StartSend();
     }
 }
Esempio n. 3
0
        public override void Send(List <byte[]> buffers)
        {
            if (this.IsDisposed)
            {
                throw new Exception("TChannel已经被Dispose, 不能发送消息");
            }
            ushort size = (ushort)buffers.Select(b => b.Length).Sum();

            byte[] sizeBuffer = BytesHelper.GetBytes(size);
            this.sendBuffer.Write(sizeBuffer, 0, sizeBuffer.Length);
            foreach (byte[] buffer in buffers)
            {
                this.sendBuffer.Write(buffer, 0, buffer.Length);
            }
            if (this.isConnected)
            {
                this.StartSend();
            }
        }