Rositsa Ruseva

Rositsa Ruseva

  • 1.4k
  • 209
  • 28.2k

Error with TcpClient and await

Jan 31 2022 10:01 PM

I have this error when I try to make the TcpClient asynchronous: 

TcpClient' does not contain a definition for 'GetAwaiter' and no accessible extension method 'GetAwaiter' accepting a first argument of type 'TcpClient' could be found (are you missing a using directive or an assembly reference?) 

public async Task StartAsync(int port)
        {
            TcpListener tcpListener = 
                new TcpListener(IPAddress.Loopback,port);
            while (true)
            {
                TcpClient tcpClient = await tcpListener.AcceptTcpClient();
                ProcessClientAsync(tcpClient);
            }
        }

Any idea how to fix it?


Answers (1)