Пример #1
0
        /// <summary>
        /// Constructs a new <see cref="WebSocketConnection"/> from an <see cref="IReadableChannel"/> and an <see cref="IWritableChannel"/> that represents an established WebSocket connection (i.e. after handshaking)
        /// </summary>
        /// <param name="inbound">A <see cref="IReadableChannel"/> from which frames will be read when receiving.</param>
        /// <param name="outbound">A <see cref="IWritableChannel"/> to which frame will be written when sending.</param>
        /// <param name="subProtocol">The sub-protocol provided during handshaking</param>
        /// <param name="options">A <see cref="WebSocketOptions"/> which provides the configuration options for the socket.</param>
        public WebSocketConnection(IReadableChannel inbound, IWritableChannel outbound, string subProtocol, WebSocketOptions options)
        {
            _inbound    = inbound;
            _outbound   = outbound;
            _options    = options;
            SubProtocol = subProtocol;

            if (_options.FixedMaskingKey != null)
            {
                // Use the fixed key directly as the buffer.
                _maskingKeyBuffer = _options.FixedMaskingKey;

                // Clear the MaskingKeyGenerator just to ensure that nobody set it.
                _options.MaskingKeyGenerator = null;
            }
            else if (_options.MaskingKeyGenerator != null)
            {
                // Establish a buffer for the random generator to use
                _maskingKeyBuffer = new byte[4];
            }

            if (_options.PingInterval > TimeSpan.Zero)
            {
                var pingIntervalMillis = (int)_options.PingInterval.TotalMilliseconds;
                // Set up the pinger
                _pinger = new Timer(Pinger, this, pingIntervalMillis, pingIntervalMillis);
            }
        }
Пример #2
0
 /// <summary>
 /// Constructs a new, <see cref="WebSocketConnection"/> from an <see cref="IReadableChannel"/> and an <see cref="IWritableChannel"/> that represents an established WebSocket connection (i.e. after handshaking)
 /// </summary>
 /// <param name="inbound">A <see cref="IReadableChannel"/> from which frames will be read when receiving.</param>
 /// <param name="outbound">A <see cref="IWritableChannel"/> to which frame will be written when sending.</param>
 /// <param name="options">A <see cref="WebSocketOptions"/> which provides the configuration options for the socket.</param>
 public WebSocketConnection(IReadableChannel inbound, IWritableChannel outbound, WebSocketOptions options) : this(inbound, outbound, subProtocol : string.Empty, options : options)
 {
 }