Esempio n. 1
0
        public async Task ProcessWebSocketRequestAsync(WebSocket webSocket, Option <EndPoint> localEndPoint, EndPoint remoteEndPoint, string correlationId)
        {
            try
            {
                var taskCompletion = new TaskCompletionSource <bool>();

                string localEndpointValue = localEndPoint.Expect(() => new ArgumentNullException(nameof(localEndPoint))).ToString();
                var    transport          = new ServerWebSocketTransport(webSocket, localEndpointValue, remoteEndPoint.ToString(), correlationId);
                transport.Open();

                var args = new TransportAsyncCallbackArgs {
                    Transport = transport, CompletedSynchronously = false
                };
                this.OnTransportAccepted(args);

                Events.EstablishedConnection(correlationId);

                transport.Closed += (sender, eventArgs) =>
                {
                    taskCompletion.SetResult(true);
                };

                //wait until websocket is closed
                await taskCompletion.Task;
            }
            catch (Exception ex) when(!ex.IsFatal())
            {
                Events.FailedAcceptWebSocket(correlationId, ex);
                throw;
            }
        }
Esempio n. 2
0
        public async Task ProcessWebSocketRequestAsync(WebSocket webSocket, Option <EndPoint> localEndPoint, EndPoint remoteEndPoint, string correlationId, X509Certificate2 clientCert, IList <X509Certificate2> clientCertChain, IAuthenticator proxyAuthenticator = null)
        {
            try
            {
                var taskCompletion = new TaskCompletionSource <bool>();

                string localEndpointValue = localEndPoint.Expect(() => new ArgumentNullException(nameof(localEndPoint))).ToString();
                ServerWebSocketTransport transport;
                if ((clientCert != null) && (clientCertChain != null))
                {
                    transport = new ServerWebSocketTransport(
                        webSocket,
                        localEndpointValue,
                        remoteEndPoint.ToString(),
                        correlationId,
                        clientCert,
                        clientCertChain,
                        proxyAuthenticator ?? this.authenticator,
                        this.clientCredentialsFactory);
                }
                else
                {
                    transport = new ServerWebSocketTransport(
                        webSocket,
                        localEndpointValue,
                        remoteEndPoint.ToString(),
                        correlationId);
                }

                transport.Open();

                var args = new TransportAsyncCallbackArgs {
                    Transport = transport, CompletedSynchronously = false
                };
                this.OnTransportAccepted(args);

                Events.EstablishedConnection(correlationId);

                transport.Closed += (sender, eventArgs) => { taskCompletion.SetResult(true); };

                // wait until websocket is closed
                await taskCompletion.Task;
            }
            catch (Exception ex) when(!ex.IsFatal())
            {
                Events.FailedAcceptWebSocket(correlationId, ex);
                throw;
            }
        }