Roman Starkov
Roman Starkov

Reputation: 61510

How to receive data after initiating TCP connection close?

TCP allows one side to issue a "FIN", and have the other side respond with some data before ending its side of the connection.

How can I achieve this using .NET's TcpClient? It appears that I must use Close to issue a FIN, but after that I can no longer call Client.Receive since Client is set to null by Close.

Upvotes: 2

Views: 158

Answers (2)

Roman Starkov
Roman Starkov

Reputation: 61510

The way to do this in .NET is to call

Socket.Shutdown(SocketShutdown.Send);

or, if you're using a TcpClient:

TcpClient.Client.Shutdown(SocketShutdown.Send);

Upvotes: 0

user207421
user207421

Reputation: 311050

Issue a shutdown for output. That sends the FIN and stops you writing anything else but it leaves the other half of the connection open.

Upvotes: 2

Related Questions