public WebSocketImplementation(Guid id, bool isClient, Func <MemoryStream> recycledStreamFactory, Stream stream, WebSocketOptions options, Uri requestUri, EndPoint remoteEndPoint, EndPoint localEndPoint)
        {
            if (options.KeepAliveInterval.Ticks < 0)
            {
                throw new ArgumentException("KeepAliveInterval must be Zero or positive", nameof(options));
            }

            this.ID       = id;
            this.IsClient = isClient;
            this.IncludeExceptionInCloseResponse = options.IncludeExceptionInCloseResponse;
            this.KeepAliveInterval = options.KeepAliveInterval;
            this.RequestUri        = requestUri;
            this.RemoteEndPoint    = remoteEndPoint;
            this.LocalEndPoint     = localEndPoint;

            this._recycledStreamFactory = recycledStreamFactory ?? WebSocketHelper.GetRecyclableMemoryStreamFactory();
            this._stream      = stream;
            this._state       = WebSocketState.Open;
            this._subProtocol = options.SubProtocol;
            this._readingCTS  = new CancellationTokenSource();

            if (this.KeepAliveInterval == TimeSpan.Zero)
            {
                Events.Log.KeepAliveIntervalZero(this.ID);
            }
            else
            {
                this._pingpongManager = new PingPongManager(this, this._readingCTS.Token);
            }
        }
示例#2
0
        internal WebSocketImplementation(Guid guid, Func <MemoryStream> recycledStreamFactory, Stream stream, TimeSpan keepAliveInterval, string secWebSocketExtensions, bool includeExceptionInCloseResponse, bool isClient)
        {
            _guid = guid;
            _recycledStreamFactory = recycledStreamFactory;
            _stream          = stream;
            _isClient        = isClient;
            _internalReadCts = new CancellationTokenSource();
            _state           = WebSocketState.Open;

            if (secWebSocketExtensions?.IndexOf("permessage-deflate") >= 0)
            {
                _usePerMessageDeflate = true;
                Events.Log.UsePerMessageDeflate(guid);
            }
            else
            {
                Events.Log.NoMessageCompression(guid);
            }

            KeepAliveInterval = keepAliveInterval;
            _includeExceptionInCloseResponse = includeExceptionInCloseResponse;
            if (keepAliveInterval.Ticks < 0)
            {
                throw new InvalidOperationException("KeepAliveInterval must be Zero or positive");
            }

            if (keepAliveInterval == TimeSpan.Zero)
            {
                Events.Log.KeepAliveIntervalZero(guid);
            }
            else
            {
                _pingPongManager = new PingPongManager(guid, this, keepAliveInterval, _internalReadCts.Token);
            }
        }
示例#3
0
        internal WebSocketImplementation(Guid guid, Func <MemoryStream> recycledStreamFactory, System.IO.Stream stream,
                                         TimeSpan keepAliveInterval, string secWebSocketExtensions, bool includeExceptionInCloseResponse,
                                         bool isClient, string subProtocol)
        {
            _guid = guid;
            _recycledStreamFactory = recycledStreamFactory;
            _stream          = stream;
            _isClient        = isClient;
            _subProtocol     = subProtocol;
            _internalReadCts = new CancellationTokenSource();
            _state           = WebSocketState.Open;
            _readCursor      = new WebSocketReadCursor(null, 0, 0);

            if (secWebSocketExtensions?.IndexOf("permessage-deflate") >= 0)
            {
                _usePerMessageDeflate = true;
            }

            KeepAliveInterval = keepAliveInterval;
            _includeExceptionInCloseResponse = includeExceptionInCloseResponse;
            if (keepAliveInterval.Ticks < 0)
            {
                throw new InvalidOperationException("KeepAliveInterval must be Zero or positive");
            }

            if (keepAliveInterval != TimeSpan.Zero)
            {
                _pingPongManager = new PingPongManager(guid, this, keepAliveInterval, _internalReadCts.Token);
            }
        }