示例#1
0
        private async Task Listen(CancellationToken token)
        {
            Console.WriteLine("SocketServer starting...");
            while (!token.IsCancellationRequested)
            {
                try
                {
                    var socket = await Server.AcceptWebSocketAsync(token).ConfigureAwait(false);

                    Console.WriteLine("Accepting new client");
                    if (socket != null)
                    {
                        HandleSocket(socket, token);
                    }
                }
                catch
                {
                    // ignored
                }
            }

            Console.WriteLine("Server Stop accepting clients");
        }