如何发起TCP连接关闭后接收数据? [英] How to receive data after initiating TCP connection close?

查看:212
本文介绍了如何发起TCP连接关闭后接收数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的TCP允许一侧发出FIN,并有结束连接其侧前与一些数据的另一侧作出响应。

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

我怎样才能做到这一点使用.NET的的TcpClient ?看来,我必须使用关闭发出一个FIN,但在那之后我再也不能叫 Client.Receive 客户端设置为关闭

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.

推荐答案

做到这一点。NET中的方法是调用

The way to do this in .NET is to call

Socket.Shutdown(SocketShutdown.Send);

或者,如果您使用的是的TcpClient

TcpClient.Client.Shutdown(SocketShutdown.Send);

这篇关于如何发起TCP连接关闭后接收数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆