Beispiel #1
0
        public bool SendAsync(byte[] bytes)
        {
            SendBuffer.StartPacket();
            // 写入包头
            SendBuffer.Buffer.WriteInt16(Packet.HEAD);
            // 写入包长
            SendBuffer.Buffer.WriteInt32(bytes.Length);
            // 写入数据
            SendBuffer.Buffer.WriteBytes(bytes, 0, bytes.Length);
            SendBuffer.EndPacket();
            bool result = true;

            if (!mSendAsync)
            {
                int count  = 0;
                int offset = 0;
                if (SendBuffer.GetFirstPacket(ref offset, ref count))
                {
                    mSendAsync = true;
                    SendEventArgs.SetBuffer(SendBuffer.Buffer.Bytes, offset, count);
                    result = AsyncNet.SendAsync(this);
                }
            }
            return(result);
        }
Beispiel #2
0
        private bool SendData()
        {
            int count  = 0;
            int offset = 0;

            if (SendBuffer.GetFirstPacket(ref offset, ref count))
            {
                isSending = true;
                SendEventArgs.SetBuffer(SendBuffer.Buffer.Bytes, offset, count);
                return(AsyncSocket.SendAsync(this));
            }
            return(true);
        }
Beispiel #3
0
        public bool SendAsyncCompleted()
        {
            ActiveDateTime = DateTime.UtcNow;
            mSendAsync     = false;
            SendBuffer.ClearFirstPacket(); //清除已发送的包
            int offset = 0;
            int count  = 0;

            if (SendBuffer.GetFirstPacket(ref offset, ref count))
            {
                mSendAsync = true;
                // 设置发送的数据包
                SendEventArgs.SetBuffer(SendBuffer.Buffer.Bytes, offset, count);
                return(AsyncNet.SendAsync(this));
            }
            else
            {
                return(true);
            }
        }