TcpClient creates a Socket to send and receive data over a network. Classes deriving from TcpClient can use this property to get or set this Socket . Use the underlying Socket returned from Client if you require access beyond that which TcpClient provides.
The TcpClient class provides simple methods for connecting, sending, and receiving stream data over a network in synchronous blocking mode. In order for TcpClient to connect and exchange data, a TcpListener or Socket created with the TCP ProtocolType must be listening for incoming connection requests.
Socket connection is used for continues exchange of data between nodes (it creates a session between them) but TCP connection makes a reliable transmission of data segments between nodes.
Sockets are faster than web services in general. However, on this last point as you're on a slow, unstable wifi connection it is not bad to reconnect for each request.
The use of TcpClient and TcpListener just means a few less lines of code. As you say it's just a wrapper over the Socket class so there is no performance difference between them it's purely a style choice.
Update: Since this answer was posted the .Net source code has become available. It does indeed show that TcpClient is a very light wrapper over the Socket class which is itself a wrapper on top of the native WinSock2 API*.
Also, you can access the socket directly from the TCPClient
object, it's under the property Client
- so there is no performance difference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With