Rositsa Ruseva

Rositsa Ruseva

  • 2k
  • 84
  • 3.5k

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();

Any idea how to fix it?

Answers (1)