コード例 #1
0
        public ClientSession(StreamSocket clientSocket)
        {
            if (clientSocket == null) throw new ArgumentNullException(nameof(clientSocket));

            _clientSocket = clientSocket;

            _httpClientSession = new HttpClientSession(clientSocket, _cancellationTokenSource, HandleHttpRequest, UpgradeToWebSocketSession);
        }
コード例 #2
0
        private void UpgradeToWebSocketSession(UpgradedToWebSocketSessionEventArgs eventArgs)
        {
            _httpClientSession = null;

            _webSocketClientSession = new WebSocketClientSession(_clientSocket);
            _webSocketClientSession.Closed += OnWebSocketClientSessionClosed;

            var webSocketConnectedEventArgs = new WebSocketConnectedEventArgs(eventArgs.HttpRequest, _webSocketClientSession);

            try
            {
                WebSocketConnected?.Invoke(this, webSocketConnectedEventArgs);
            }
            finally
            {
                if (!webSocketConnectedEventArgs.IsHandled)
                {
                    _cancellationTokenSource.Cancel();
                }
            }
        }