Exemplo n.º 1
0
        /// <summary>
        /// Accepts the connection and creates a new Client Session.
        /// </summary>
        private static async void OnAcceptSocket()
        {
            while (IsAlive)
            {
                Log.Inform("Aceitando socket...");

                var cSocket = await Listener.AcceptSocketAsync();

                ClientSession session = new ClientSession(cSocket);

                Log.Inform("Conexão com socket iniciada. IP: {0}", session.Label);
            }
        }
Exemplo n.º 2
0
        private async Task AcceptAsync()
        {
            Socket socket = await Listener.AcceptSocketAsync();

            Logger.Log($"一个客户端连接进来了!{socket.RemoteEndPoint}");

            Client client = GetClient();

            if (client is null)
            {
                socket.Close();
                Logger.Log("无可用连接", LogLevel.Warn);
            }
            else
            {
                client.Use(socket);
            }
            Logger.Log($"剩余可用数量:{FreeClients.Count}");
            await AcceptAsync();
        }