11

Hello i would like to ask what is difference between using this :

public TcpListener Listener;
public TcpClient Client;

Listener = new TcpListener(DeafultPort);
Client = default(TcpClient);
Listener.Start();

and this :

serverSocket = new Socket(AddressFamily.InterNetwork, 
                                      SocketType.Stream, 
                                      ProtocolType.Tcp);

IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Any, 1000);

and also i would like to know if i use first option what is difference between

Listener.BeginAcceptSocket()

and

Listener.Server.BeginAccept()

and if i use second option what exactly does these two lines ?

serverSocket.Bind(ipEndPoint);
serverSocket.Listen(4);

Thanks for answers

Adarsh Shah
  • 6,755
  • 2
  • 25
  • 39
Vacko
  • 163
  • 2
  • 10
  • 1
    Possible duplicate of [Difference between TCP Listener and Socket](http://stackoverflow.com/questions/12361924/difference-between-tcp-listener-and-socket) – TaRDy May 05 '16 at 19:49

2 Answers2

19

The difference between Socket and TcpListener/TcpClient is that TcpListener/TcpClient is easier to use than Socket. Socket can do everything what TcpListener/TcpClient can do. If you new to network programming, TcpListener/TcpClient is recommended. For most task, TcpClient/TcpListener perform similar in performance. Only when you have problems or not enough functionality, should you consider Sockets.

I know that my answer is not technically correct, but in this context, that would suffice.

Syaiful Nizam Yahya
  • 4,196
  • 11
  • 51
  • 71
0

For any serious solution use Sockets and not TcpClient. It provides much more control and when using Tasks or threads and asynchronous methods with byte buffers usually a necessity.

grockland
  • 9
  • 2