Search code examples
c#socketstcpclient

TcpClient equivalent for Socket Shutdown Send or Receive


Concerning System.Net.TcpClient

I was wondering if it is possible to perform an individual shutdown on the outputstream or inputstream from a TcpClient. I know, that the NetworkStream can be grepped with aTcpClient.GetStream() however, I am still figuring out to Close() the inbound or outbound part of it, without closing the entire Networkstream.

This is possible with the more basic System.Net.Socket class in which I could first send data and afterwards close it with SocketShutdown.Send while keeping the inputstream open untill I close it with SocketShutdown.Receive.

Reference links:

MSDN on System.Net.Socket.shutdown()

MSDN on System.Net.TcpClient


Solution

  • TcpClient has a Client property, which is of the type Socket.

    Use the property to get Socket, so you can call Shutdown().