Example #1
0
        public FramedClient(IRawByteClient client)
        {
            this.client = client;
            this.recvBuffer = new ResizableCyclicBuffer(4096);

            this.client.Received += ClientReceivedData;
        }
Example #2
0
        public FramedClient(IRawByteClient client)
        {
            this.received   = new Subject <ArraySegment <byte> >();
            this.client     = client;
            this.recvBuffer = new ResizableCyclicBuffer(4096);

            this.client.Received.Subscribe(ClientReceivedData);
        }
Example #3
0
        public FramedClient(IRawByteClient client)
        {
            this.received = new Subject<ArraySegment<byte>>();
            this.client = client;
            this.recvBuffer = new ResizableCyclicBuffer(4096);

            this.client.Received.Subscribe(ClientReceivedData);
        }
Example #4
0
 public RawByteClientStream(IRawByteClient client)
 {
     this.disposed = false;
     this.hasDataEvent = new ManualResetEventSlim();
     this.client = client;
     this.buffer = new ResizableCyclicBuffer(4096);
     this.client.Received += DataReceived;
 }
 public RawByteClientStream(IRawByteClient client)
 {
     this.disposed     = false;
     this.hasDataEvent = new ManualResetEventSlim();
     this.client       = client;
     this.buffer       = new ResizableCyclicBuffer(4096);
     this.client.Received.Subscribe(DataReceived);
 }
Example #6
0
        /// <summary>
        /// Initialises ssl client as a client side endpoint.
        /// </summary>
        public SslClient(IRawByteClient client,
                         string targetHost,
                         RemoteCertificateValidationCallback remoteCertificateValidationCallback)
        {
            Ensure.IsNotNull(client, "client");
            Ensure.IsNotNullOrWhiteSpace(targetHost, "targetHost");

            InitializeAsClient(client, targetHost, remoteCertificateValidationCallback);
        }
Example #7
0
        /// <summary>
        /// Initialises ssl client as a client side endpoint.
        /// </summary>
        public SslClient(IRawByteClient client,
                         string targetHost,
                         RemoteCertificateValidationCallback remoteCertificateValidationCallback)
        {
            Ensure.IsNotNull(client, "client");
            Ensure.IsNotNullOrWhiteSpace(targetHost, "targetHost");

            InitializeAsClient(client, targetHost, remoteCertificateValidationCallback);
        }
Example #8
0
        /// <summary>
        /// Initialises ssl client as a client side endpoint.
        /// </summary>
        public SslClient(IRawByteClient client, string targetHost, bool allowEveryCertificate)
        {
            Ensure.IsNotNull(client, "client");
            Ensure.IsNotNullOrWhiteSpace(targetHost, "targetHost");

            if (allowEveryCertificate)
                InitializeAsClient(client, targetHost, AllowEveryCertificate);
            else
                InitializeAsClient(client, targetHost, null);
        }
Example #9
0
        private void InitializeAsServer(IRawByteClient client,
                                        X509Certificate certificate)
        {
            InitializeCommon(client, isClient: false);

            this.serverCertificate   = certificate;
            this.clientStreamWrapper = new RawByteClientStream(this.client);
            this.sslStream           = new SslStream(
                this.clientStreamWrapper,
                true);
        }
Example #10
0
        /// <summary>
        /// Initialises ssl client as a server side endpoint.
        /// It is assumed, that passed client is already connected.
        /// EstablishSsl should be called when this constructor is used.
        /// </summary>
        public SslClient(IRawByteClient client,
                         X509Certificate serverCertificate)
        {
            Ensure.IsNotNull(client, "client");
            Ensure.IsNotNull(serverCertificate, "serverCertificate");

            if (!client.IsConnected)
                throw new InvalidOperationException("Socket client should be connected");

            InitializeAsServer(client, serverCertificate);
        }
Example #11
0
        /// <summary>
        /// Initialises ssl client as a server side endpoint.
        /// It is assumed, that passed client is already connected.
        /// EstablishSsl should be called when this constructor is used.
        /// </summary>
        public SslClient(IRawByteClient client,
                         X509Certificate serverCertificate)
        {
            Ensure.IsNotNull(client, "client");
            Ensure.IsNotNull(serverCertificate, "serverCertificate");

            if (!client.IsConnected)
            {
                throw new InvalidOperationException("Socket client should be connected");
            }

            InitializeAsServer(client, serverCertificate);
        }
Example #12
0
        /// <summary>
        /// Initialises ssl client as a client side endpoint.
        /// </summary>
        public SslClient(IRawByteClient client, string targetHost, bool allowEveryCertificate)
        {
            Ensure.IsNotNull(client, "client");
            Ensure.IsNotNullOrWhiteSpace(targetHost, "targetHost");

            if (allowEveryCertificate)
            {
                InitializeAsClient(client, targetHost, AllowEveryCertificate);
            }
            else
            {
                InitializeAsClient(client, targetHost, null);
            }
        }
Example #13
0
        private void InitializeCommon(IRawByteClient client,
                                      bool isClient)
        {
            this.connected    = new AsyncSubject <Unit>();
            this.disconnected = new AsyncSubject <Exception>();
            this.sent         = new Subject <int>();
            this.received     = new Subject <ArraySegment <byte> >();

            this.isClient         = isClient;
            this.disconnectCalled = false;
            this.client           = client;

            this.client.Disconnected.Subscribe(ClientDisconnected);
            this.client.Connected.Subscribe(_ => ClientConnected());
            this.client.Sent.Subscribe(ClientSentData);
        }
Example #14
0
        public static byte[] ReceiveData(this IRawByteClient client, int totalExpectedBytes, int timeout,
                                         Action sendAction)
        {
            var ev     = new ManualResetEventSlim();
            var buffer = new List <byte>();

            client.Received.Subscribe(bs =>
            {
                lock (buffer)
                {
                    buffer.AddRange(bs);
                }
            });

            sendAction();

            var sw = Stopwatch.StartNew();

            while (true)
            {
                lock (buffer)
                {
                    if (buffer.Count == totalExpectedBytes)
                    {
                        break;
                    }
                }

                Thread.Sleep(50);

                if (sw.ElapsedMilliseconds > timeout)
                {
                    throw new TimeoutException();
                }
            }

            lock (buffer)
            {
                return(buffer.ToArray());
            }
        }
Example #15
0
        private void InitializeAsClient(IRawByteClient client,
                                        string targetHost,
                                        RemoteCertificateValidationCallback remoteCertificateValidationCallback)
        {
            InitializeCommon(client, isClient: true);

            this.targetHost          = targetHost;
            this.clientStreamWrapper = new RawByteClientStream(this.client);
#if !MONO
            this.sslStream = new SslStream(
                this.clientStreamWrapper,
                true,
                remoteCertificateValidationCallback,
                null,
                EncryptionPolicy.RequireEncryption);
#else
            this.sslStream = new SslStream(
                this.clientStreamWrapper,
                true,
                remoteCertificateValidationCallback,
                null);
#endif
        }
Example #16
0
 /// <summary>
 /// Initialises ssl client as a client side endpoint.
 /// </summary>
 public SslClient(IRawByteClient client, string targetHost)
     : this(client, targetHost, allowEveryCertificate : false)
 {
 }
Example #17
0
 /// <summary>
 /// Initialises ssl client as a client side endpoint.
 /// </summary>
 public SslClient(IRawByteClient client, string targetHost)
     : this(client, targetHost, allowEveryCertificate: false)
 { }
Example #18
0
        private void InitializeCommon(IRawByteClient client,
                                bool isClient)
        {
            this.connected = new AsyncSubject<Unit>();
            this.disconnected = new AsyncSubject<Exception>();
            this.sent = new Subject<int>();
            this.received = new Subject<ArraySegment<byte>>();

            this.isClient = isClient;
            this.disconnectCalled = false;
            this.client = client;

            this.client.Disconnected.Subscribe(ClientDisconnected);
            this.client.Connected.Subscribe(_ => ClientConnected());
            this.client.Sent.Subscribe(ClientSentData);
        }
Example #19
0
        private void InitializeAsClient(IRawByteClient client,
                                        string targetHost,
                                        RemoteCertificateValidationCallback remoteCertificateValidationCallback)
        {
            InitializeCommon(client, isClient: true);

            this.targetHost = targetHost;
            this.clientStreamWrapper = new RawByteClientStream(this.client);
#if !MONO
            this.sslStream = new SslStream(
                this.clientStreamWrapper,
                true,
                remoteCertificateValidationCallback,
                null,
                EncryptionPolicy.RequireEncryption);
#else
            this.sslStream = new SslStream(
                this.clientStreamWrapper,
                true,
                remoteCertificateValidationCallback,
                null);
#endif
        }
Example #20
0
        private void InitializeAsServer(IRawByteClient client,
                                        X509Certificate certificate)
        {
            InitializeCommon(client, isClient: false);

            this.serverCertificate = certificate;
            this.clientStreamWrapper = new RawByteClientStream(this.client);
            this.sslStream = new SslStream(
                this.clientStreamWrapper,
                true);
        }
Example #21
0
        private void InitializeCommon(IRawByteClient client,
                                bool isClient)
        {
            this.connectedTcs = new TaskCompletionSource<int>();
            this.isClient = isClient;
            this.disconnectCalled = false;
            this.client = client;

            this.client.Disconnected += ClientDisconnected;
            this.client.Connected += ClientConnected;
            this.client.Sent += ClientSentData;
        }