Exemplo n.º 1
0
        private void DoWebSocketUpgrade(IDictionary <string, object> acceptOptions, WebSocketFunc callback)
        {
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }

            _environment[Constants.ResponseStatusCodeKey] = 101;
            _acceptOptions = acceptOptions;
            _webSocketFunc = callback;

            string subProtocol = GetWebSocketSubProtocol();

            PrepareResponse();

            // TODO: Other parameters?
            _webSocketAction = _context.AcceptWebSocketAsync(subProtocol)
                               .Then(webSocketContext =>
            {
                var wrapper = new WebSockets.OwinWebSocketWrapper(webSocketContext,
                                                                  _environment.Get <CancellationToken>(Constants.CallCancelledKey));
                return(_webSocketFunc(wrapper.Environment)
                       .Then(() => wrapper.CleanupAsync()));
            });
        }
Exemplo n.º 2
0
        private async Task WebSocketUpgrade(string subProtocol, int receiveBufferSize, TimeSpan keepAliveInterval, ArraySegment <byte>?internalBuffer)
        {
            HttpListenerWebSocketContext context;

            if (!internalBuffer.HasValue)
            {
                context = await _context.AcceptWebSocketAsync(subProtocol, receiveBufferSize, keepAliveInterval);
            }
            else
            {
                context = await _context.AcceptWebSocketAsync(subProtocol, receiveBufferSize, keepAliveInterval, internalBuffer.Value);
            }

            var wrapper = new WebSockets.OwinWebSocketWrapper(context, _environment.Get <CancellationToken>(Constants.CallCancelledKey));

            await _webSocketFunc(wrapper.Environment);

            await wrapper.CleanupAsync();
        }
        private async Task WebSocketUpgrade(string subProtocol, int receiveBufferSize, TimeSpan keepAliveInterval, ArraySegment<byte>? internalBuffer)
        {
            HttpListenerWebSocketContext context;
            if (!internalBuffer.HasValue)
            {
                context = await _context.AcceptWebSocketAsync(subProtocol, receiveBufferSize, keepAliveInterval);
            }
            else
            {
                context = await _context.AcceptWebSocketAsync(subProtocol, receiveBufferSize, keepAliveInterval, internalBuffer.Value);
            }

            var wrapper = new WebSockets.OwinWebSocketWrapper(context, _environment.Get<CancellationToken>(Constants.CallCancelledKey));
            await _webSocketFunc(wrapper.Environment);
            await wrapper.CleanupAsync();
        }
Exemplo n.º 4
0
        private void DoWebSocketUpgrade(IDictionary<string, object> acceptOptions, WebSocketFunc callback)
        {
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }

            _environment[Constants.ResponseStatusCodeKey] = 101;
            _acceptOptions = acceptOptions;
            _webSocketFunc = callback;

            string subProtocol = GetWebSocketSubProtocol();

            PrepareResponse();

            // TODO: Other parameters?
            _webSocketAction = _context.AcceptWebSocketAsync(subProtocol)
                .Then(webSocketContext =>
                {
                    var wrapper = new WebSockets.OwinWebSocketWrapper(webSocketContext,
                        _environment.Get<CancellationToken>(Constants.CallCancelledKey));
                    return _webSocketFunc(wrapper.Environment)
                        .Then(() => wrapper.CleanupAsync());
                });
        }