Networking: TcpClient vs. Socket

L

Laurent

Hi,
I am new to C# and .NET.

On a TcpListener I can choose between AcceptSocket and AcceptTcpClient.
These 2 classes look very similar:
* on TcpClient you call GetStream (and Read and Write the NetworkStream)
* on Socket you can Send and Receive directly

Which is best?

Thanks.
 
C

Christopher Kimbell

Hi,

Socket is the raw option, all operations use byte buffers, and the
constructor uses an IPEndPoint.

The TCPClient hides all these low level details. The contstructor takes a
string that can either represent an IP address or more readable address e.g
www.microsoft.com As you observed TCPClient gives you a Stream class, this
can be fed into other .NET classes, e.g. XMLReader.

The TCPClient is a convenience class, if all you wan't to do is to set up a
TCP connection, use it. If you require more control over your connection use
the Socket.


Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top