How to receive data after initiating TCP connectio

2019-07-18 04:18发布

问题:

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.

回答1:

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.



回答2:

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);


标签: .net tcp