void receiveSocket_OnReceived(object sender, SocketAsyncEventArgs e)
        {
            SocketToken sToken = new SocketToken()
            {
                TokenSocket = e.ConnectSocket
            };

            ReceiveOffsetHanlder?.Invoke(sToken, e.Buffer, e.Offset, e.BytesTransferred);

            if (ReceiveCallbackHandler != null)
            {
                if (e.BytesTransferred > 0)
                {
                    if (e.Offset == 0 && e.BytesTransferred == e.Buffer.Length)
                    {
                        ReceiveCallbackHandler(sToken, e.Buffer);
                    }
                    else
                    {
                        byte[] realBytes = new byte[e.BytesTransferred];
                        Buffer.BlockCopy(e.Buffer, e.Offset, realBytes, 0, e.BytesTransferred);
                        ReceiveCallbackHandler(sToken, realBytes);
                    }
                }
            }
        }
Beispiel #2
0
        private void receiveSocket_OnReceived(object sender, SocketAsyncEventArgs e)
        {
            if (IsClientRequest(e))
            {
                return;
            }

            SocketToken sToken = new SocketToken()
            {
                TokenIpEndPoint = (IPEndPoint)e.RemoteEndPoint
            };

            ReceiveOffsetHanlder?.Invoke(sToken, e.Buffer, e.Offset, e.BytesTransferred);

            if (ReceiveCallbackHandler != null)
            {
                if (e.BytesTransferred > 0)
                {
                    if (e.Offset == 0 && e.BytesTransferred == e.Buffer.Length)
                    {
                        ReceiveCallbackHandler(sToken, e.Buffer);
                    }
                    else
                    {
                        byte[] realBytes = new byte[e.BytesTransferred];
                        Buffer.BlockCopy(e.Buffer, e.Offset, realBytes, 0, e.BytesTransferred);
                        ReceiveCallbackHandler(sToken, realBytes);
                    }
                }
            }
        }