11

I want to write a simple multi threaded server-client application and I've stumbled on those two while creating tcplistenr

public void serverListenr
{
        int MessageLength=0;
        TcpListener peerListener = _infrastructure_TcpServerAndClient.CreateNewTcpListenerANDstart();
        while (true)
        {
            //var Client = peerListener.AcceptTcpClient or   peerListener.AcceptSocket(); ?? 
           new Thread(ServeData).Start(client);
        }
....
}

they have the same description

What is the difference between those two ?

LordTitiKaka
  • 2,087
  • 2
  • 31
  • 51

1 Answers1

13

AcceptTcpClient returns TcpClient, whereas AcceptSocket returns a Socket. Due to this, they can also throw different errors

Naturally your next question will be what's the difference between those two. TcpClient is a wrapper around a Socket, with some minor performance implications. See this.

Luke Girvin
  • 13,221
  • 9
  • 64
  • 84
Prescott
  • 7,312
  • 5
  • 49
  • 70