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 WebSocketListenerConfig(WebSocketListenerOptions options)
 {
     options.CheckCoherence();
     Options = options.Clone();
     ConnectionExtensions = new WebSocketConnectionExtensionCollection();
     Standards            = new WebSocketFactoryCollection();
     MessageExtensions    = new WebSocketMessageExtensionCollection();
 }
        internal WebSocketConnectionExtensionCollection Clone()
        {
            var cloned = new WebSocketConnectionExtensionCollection();

            foreach (var item in this.extensions)
            {
                cloned.extensions.Add(item.Clone());
            }
            return(cloned);
        }
Example #6
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);
        }