TcpListener vs Socket

Hello, I would like to ask what is the 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 am using the first option, what is the difference between

 Listener.BeginAcceptSocket() 

and

 Listener.Server.BeginAccept() 

and if I use the second option, what exactly are these two lines?

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

thanks for answers

+7
c # sockets
source share
1 answer

The difference between Socket and TcpListener / TcpClient is that TcpListener / TcpClient is easier to use than Socket. Socket can do everything TcpListener / TcpClient can do. If you are new to network programming, TcpListener / TcpClient is recommended. For most tasks, TcpClient / TcpListener does a similar job. If you have problems or lack of functionality, you should consider Sockets.

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

+12
source share

All Articles