public WebSocketListener(IPEndPoint endpoint, WebSocketListenerOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            if (endpoint == null)
            {
                throw new ArgumentNullException("endpoint");
            }

            options.CheckCoherence();
            _options = options.Clone();
            _cancel  = new CancellationTokenSource();

            _listener = new TcpListener(endpoint);
            if (_options.UseNagleAlgorithm.HasValue)
            {
                _listener.Server.NoDelay = !_options.UseNagleAlgorithm.Value;
            }

            ConnectionExtensions = new WebSocketConnectionExtensionCollection(this);
            Standards            = new WebSocketFactoryCollection(this);
            Func <Socket, Task <WebSocketNegotiationResult> > negotiate = NegotiateWebSocket;

            _negotiationQueue = new TransformBlock <Socket, WebSocketNegotiationResult>(negotiate, new ExecutionDataflowBlockOptions()
            {
                CancellationToken = _cancel.Token, MaxDegreeOfParallelism = options.ParallelNegotiations, BoundedCapacity = options.NegotiationQueueCapacity
            });

            _handShaker = new WebSocketHandshaker(Standards, _options);
        }
        public WebSocketListener(IPEndPoint endpoint, WebSocketListenerOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            if (endpoint == null)
            {
                throw new ArgumentNullException("endpoint");
            }

            options.CheckCoherence();
            _options = options.Clone();
            _cancel  = new CancellationTokenSource();

            _listener = new TcpListener(endpoint);
            if (_options.UseNagleAlgorithm.HasValue)
            {
                _listener.Server.NoDelay = !_options.UseNagleAlgorithm.Value;
            }

            ConnectionExtensions = new WebSocketConnectionExtensionCollection(this);
            Standards            = new WebSocketFactoryCollection(this);

            _negotiationQueue = new HttpNegotiationQueue(Standards, ConnectionExtensions, options);
        }
        public WebSocketListener(IPEndPoint endpoint, WebSocketListenerOptions options)
        {
            Guard.ParameterCannotBeNull(endpoint, "endpoint");
            Guard.ParameterCannotBeNull(options, "options");
            
            options.CheckCoherence();
            _options = options.Clone();
            _cancel = new CancellationTokenSource();

#if NETSTANDARD || UAP
            _listener = new TcpListener(endpoint);
#else
            if (Type.GetType("Mono.Runtime") == null && _options.UseDualStackSocket)
                _listener = TcpListener.Create(endpoint.Port);
            else
                _listener = new TcpListener(endpoint);
#endif

            if (_options.UseNagleAlgorithm.HasValue)
                _listener.Server.NoDelay = !_options.UseNagleAlgorithm.Value;

            ConnectionExtensions = new WebSocketConnectionExtensionCollection(this);
            Standards = new WebSocketFactoryCollection(this);

            _negotiationQueue = new HttpNegotiationQueue(Standards, ConnectionExtensions, options);
        }
        public WebSocketListener(IPEndPoint endpoint, WebSocketListenerOptions options)
        {
            Guard.ParameterCannotBeNull(endpoint, "endpoint");
            Guard.ParameterCannotBeNull(options, "options");

            options.CheckCoherence();
            _options = options.Clone();
            _cancel  = new CancellationTokenSource();

#if NETSTANDARD || UAP
            _listener = new TcpListener(endpoint);
#else
            if (Type.GetType("Mono.Runtime") == null && _options.UseDualStackSocket)
            {
                _listener = TcpListener.Create(endpoint.Port);
            }
            else
            {
                _listener = new TcpListener(endpoint);
            }
#endif

            if (_options.UseNagleAlgorithm.HasValue)
            {
                _listener.Server.NoDelay = !_options.UseNagleAlgorithm.Value;
            }

            ConnectionExtensions = new WebSocketConnectionExtensionCollection(this);
            Standards            = new WebSocketFactoryCollection(this);

            _negotiationQueue = new HttpNegotiationQueue(Standards, ConnectionExtensions, options);
        }
 public WebSocketListenerConfig(WebSocketListenerOptions options)
 {
     options.CheckCoherence();
     Options = options.Clone();
     ConnectionExtensions = new WebSocketConnectionExtensionCollection();
     Standards            = new WebSocketFactoryCollection();
     MessageExtensions    = new WebSocketMessageExtensionCollection();
 }
        public WebSocketListener(IPEndPoint endpoint, WebSocketListenerOptions options)
        {
            Guard.ParameterCannotBeNull(endpoint, "endpoint");
            Guard.ParameterCannotBeNull(options, "options");
            
            options.CheckCoherence();
            _options = options.Clone();
            _cancel = new CancellationTokenSource();

            _listener = new TcpListener(endpoint);
            if(_options.UseNagleAlgorithm.HasValue)
                _listener.Server.NoDelay = !_options.UseNagleAlgorithm.Value;

            ConnectionExtensions = new WebSocketConnectionExtensionCollection(this);
            Standards = new WebSocketFactoryCollection(this);

            _negotiationQueue = new HttpNegotiationQueue(Standards, ConnectionExtensions, options);
        }
        public WebSocketListener(IPEndPoint endpoint, WebSocketListenerOptions options)
        {
            if (options == null)
                throw new ArgumentNullException("options");

            if (endpoint == null)
                throw new ArgumentNullException("endpoint");

            _options = options.Clone();
            _cancel = new CancellationTokenSource();
            _listener = new TcpListener(endpoint);
            
            ConnectionExtensions = new WebSocketConnectionExtensionCollection(this);
            Standards = new WebSocketFactoryCollection(this);
            Func<Socket, Task<WebSocketNegotiationResult>> negotiate = NegotiateWebSocket;
            _negotiationQueue = new TransformBlock<Socket, WebSocketNegotiationResult>(negotiate, new ExecutionDataflowBlockOptions() { CancellationToken = _cancel.Token, MaxDegreeOfParallelism = options.ParallelNegotiations, BoundedCapacity = options.NegotiationQueueCapacity });

            _handShaker = new WebSocketHandshaker(Standards, _options);
        }
Example #8
0
        public WebSocketListener(IPEndPoint endpoint, WebSocketListenerOptions options)
        {
            Guard.ParameterCannotBeNull(endpoint, "endpoint");
            Guard.ParameterCannotBeNull(options, "options");

            options.CheckCoherence();
            _options = options.Clone();
            _cancel  = new CancellationTokenSource();

            _listener = new TcpListener(endpoint);
            if (_options.UseNagleAlgorithm.HasValue)
            {
                _listener.Server.NoDelay = !_options.UseNagleAlgorithm.Value;
            }

            ConnectionExtensions = new WebSocketConnectionExtensionCollection(this);
            Standards            = new WebSocketFactoryCollection(this);

            _negotiationQueue = new HttpNegotiationQueue(Standards, ConnectionExtensions, options);
        }
        public WebSocketClient([NotNull] WebSocketListenerOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (options.Standards.Count == 0)
            {
                throw new ArgumentException("Empty list of WebSocket standards.", nameof(options));
            }

            options.CheckCoherence();
            this.options = options.Clone();
            this.options.SetUsed(true);

            if (this.options.NegotiationTimeout > TimeSpan.Zero)
            {
                this.negotiationsTimeoutQueue = new CancellationQueue(this.options.NegotiationTimeout);
            }
            if (this.options.PingMode != PingMode.Manual)
            {
                this.pingQueue = new PingQueue(options.PingInterval);
            }

            this.log        = this.options.Logger;
            this.closeEvent = new AsyncConditionSource(isSet: true)
            {
                ContinueOnCapturedContext = false
            };
            this.workCancellationSource = new CancellationTokenSource();
            this.pendingRequests        = new ConcurrentDictionary <WebSocketHandshake, Task <WebSocket> >();

            if (this.options.BufferManager == null)
            {
                this.options.BufferManager = BufferManager.CreateBufferManager(100, this.options.SendBufferSize * 2); // create small buffer pool if not configured
            }
            if (this.options.CertificateValidationHandler == null)
            {
                this.options.CertificateValidationHandler = this.ValidateRemoteCertificate;
            }
        }
        public WebSocketListener(IPEndPoint endpoint, WebSocketListenerOptions options)
        {
            if (options == null)
                throw new ArgumentNullException("options");

            if (endpoint == null)
                throw new ArgumentNullException("endpoint");
            
            options.CheckCoherence();
            _options = options.Clone();
            _cancel = new CancellationTokenSource();

            _listener = new TcpListener(endpoint);
            if(_options.UseNagleAlgorithm.HasValue)
                _listener.Server.NoDelay = !_options.UseNagleAlgorithm.Value;

            ConnectionExtensions = new WebSocketConnectionExtensionCollection(this);
            Standards = new WebSocketFactoryCollection(this);

            _negotiationQueue = new HttpNegotiationQueue(Standards, ConnectionExtensions, options);
        }
Example #11
0
        public WebSocketListener(Uri[] listenEndPoints, WebSocketListenerOptions options)
        {
            if (listenEndPoints == null)
            {
                throw new ArgumentNullException(nameof(listenEndPoints));
            }
            if (listenEndPoints.Length == 0)
            {
                throw new ArgumentException("At least one prefix should be specified.", nameof(listenEndPoints));
            }
            if (listenEndPoints.Any(p => p == null))
            {
                throw new ArgumentException("Null objects passed in array.", nameof(listenEndPoints));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            options.CheckCoherence();
            this.options = options.Clone();
            if (this.options.BufferManager == null)
            {
                this.options.BufferManager = BufferManager.CreateBufferManager(100, this.options.SendBufferSize); // create small buffer pool if not configured
            }
            if (this.options.Logger == null)
            {
                this.options.Logger = NullLogger.Instance;
            }
            this.log = this.options.Logger;

            this.listeners       = EmptyListeners;
            this.localEndPoints  = EmptyEndPoints;
            this.listenEndPoints = listenEndPoints;

            this.negotiationQueue = new HttpNegotiationQueue(options.Standards, options.ConnectionExtensions, this.options);
        }