예제 #1
0
    async void Listen(int port)
    {
        TcpClient client = null;

        try
        {
            _server = new TcpListener(IPAddress.Parse("0.0.0.0"), port);
            _server.Start();

            Debug.Log("server start at " + port);

            while (true)
            {
                client = await _server.AcceptTcpClientAsync();

                Debug.Log("client connect");

                _client = new NetWorkClient(client);
                await _client.StartReceiving();
            }
        }
        catch (Exception ex)
        {
            // display the error message or whatever
            Debug.LogException(ex);
        }
        finally
        {
            Debug.Log("close server");
            _server?.Stop();
        }
    }