Beispiel #1
0
        public void Send(byte[] packet, int offset, int length)
        {
            if (_tcpSock != null && _tcpSock.Connected)
            {
                SocketAsyncEventArgs args = SocketHelpers.AcquireSocketArg();
                if (args != null)
                {
                    args.Completed += SendAsyncComplete;

                    args.SetBuffer(packet, offset, length);
                    args.UserToken = this;
                    _tcpSock.SendAsync(args);

                    //unchecked
                    //{
                    //    _bytesSent += (uint)length;
                    //}

                    //Interlocked.Add(ref _totalBytesSent, length);
                }
                else
                {
                    Csl.Wl(string.Format("Client {0}'s SocketArgs are null", this));
                }
            }
        }
Beispiel #2
0
        private void ResumeReceive()
        {
            if (_tcpSock != null && _tcpSock.Connected)
            {
                SocketAsyncEventArgs socketArgs = SocketHelpers.AcquireSocketArg();
                //int offset = _offset + _remainingLength;

                socketArgs.SetBuffer(recvDataBuffer.Data, recvDataBuffer.Postion, BufferSize - _remainingLength);
                socketArgs.UserToken  = this;
                socketArgs.Completed += ReceiveAsyncComplete;

                bool willRaiseEvent = _tcpSock.ReceiveAsync(socketArgs);
                if (!willRaiseEvent)
                {
                    ProcessRecieve(socketArgs);
                }
            }
        }