AcceptWebSocketAsync() public method

public AcceptWebSocketAsync ( CancellationToken token ) : Task
token System.Threading.CancellationToken
return Task
 private async Task AcceptWebSocketClientsAsync(WebSocketListener server, CancellationToken token)
 {
     while (!token.IsCancellationRequested)
     {
         try
         {
             var ws = await server.AcceptWebSocketAsync(token).ConfigureAwait(false);
             if (ws != null)
                 Task.Run(() => HandleConnectionAsync(ws, token));
         }
         catch (Exception aex)
         {
             Log("Error Accepting clients: " + aex.GetBaseException().Message);
         }
     }
     Log("Server Stop accepting clients");
 }
示例#2
0
        async Task AcceptWebSocketClientsAsync(WebSocketListener server, CancellationToken token)
        {
            while (!token.IsCancellationRequested)
            {
                try
                {
                    var ws = await server.AcceptWebSocketAsync(token).ConfigureAwait(false);
                    Console.WriteLine("A new connection joined the server: " + ws.RemoteEndpoint);

                    if (ws != null)
                        Task.Run(() => HandleConnectionAsync(ws, token));
                }
                catch (Exception aex)
                {
                    Console.WriteLine("Error Accepting clients: " + aex.GetBaseException().Message);
                }
            }
            Console.WriteLine("Server Stop accepting clients");
        }
示例#3
0
        static async Task AcceptWebSocketClients(WebSocketListener server, CancellationToken token)
        {
            while (!token.IsCancellationRequested)
            {
                try
                {
                    var ws = await server.AcceptWebSocketAsync(token);
                    if (ws != null)
                        Task.Run(() => HandleConnectionAsync(ws, token));
                }
                catch (TaskCanceledException)
                {

                }
                catch (Exception aex)
                {
                    var ex = aex.GetBaseException();
                    _log.Error("AcceptWebSocketClients", ex);
                    Log("Error Accepting client: " + ex.GetType().Name +": " + ex.Message);
                }
            }
            Log("Server Stop accepting clients");
        }
 private async Task AcceptWebSocketClientsAsync(WebSocketListener server)
 {
     while (!_cancellation.IsCancellationRequested)
     {
         try
         {
             var ws = await server.AcceptWebSocketAsync(_cancellation.Token).ConfigureAwait(false);
             if (ws == null) continue;
             var handler = new WebSocketHandler(Queue, ws, _serializator, _log);
             Task.Run(() => handler.HandleConnectionAsync(_cancellation.Token));
         }
         catch (TaskCanceledException)
         {
         }
         catch (InvalidOperationException)
         {
         }
         catch (Exception aex)
         {
             _log.Error("Error Accepting clients", aex.GetBaseException());
         }
     }
     _log.Info("Server Stop accepting clients");
 }
示例#5
0
 private async Task HandleListners(WebSocketListener listener)
 {
     while (listener.IsStarted)
     {
         try
         {
             var websocket = await listener.AcceptWebSocketAsync(CancellationToken.None)
                 .ConfigureAwait(false);
             if (websocket != null)
                 Task.Run(() => HandleWebSocketAsync(websocket));
         }
         catch (Exception ex)
         {
             OnError?.Invoke(null, ex);
         }
     }
 }
示例#6
0
        static async Task AcceptWebSocketClients(WebSocketListener server, CancellationToken token)
        {
            while (!token.IsCancellationRequested)
            {
                try
                {
                    var ws = await server.AcceptWebSocketAsync(token).ConfigureAwait(false);
                    if (ws == null)
                        continue;

                    //int y = 0;

                    Interlocked.Increment(ref PerformanceCounters.Accepted);
                    Console.WriteLine("Accepted " + PerformanceCounters.Accepted);

                    //queue.Enqueue(new QueueItem { WebSocket = ws, TimeStamp = DateTime.Now});
                    //HandleConnectionAsync(ws, token);
                    //Task.Run(() => HandleConnectionAsync(ws, token));

                    Task.Factory.StartNew(() => HandleConnectionAsync(ws, token));
                }
                catch (Exception aex)
                {
                    var ex = aex.GetBaseException();
                    Log("Error AcceptWebSocketClients" + ex);
                    Log("Error Accepting client: " + ex.GetType().Name + ": " + ex.Message);
                }
            }

            Log("Server Stop accepting clients");
        }