简体   繁体   English

如果在读取字节之前断开连接,TCP套接字连接上的字节会丢失吗?

[英]Are bytes on a TCP socket connection lost if the connection is severed before the bytes are read?

If I have a Selector that's accepting sockets and pushing them to a queue for other threads to handle, and no threads takes a socket for, say two minutes, and the client pushes data but then times out and disconnects. 如果我有一个Selector的是公司的意见sockets ,并将其推到一个队列为其他线程来处理,并没有线程需要一个插座,说两分钟,客户端将数据推但随后超时并断开连接。 When a thread then takes one of those now closed sockets and tries to read from it, will it get the data that has already been sent by the client, or will there be nothing there to read? thread然后使用那些现在关闭的sockets并尝试从中读取时,它将获取客户端已发送的数据,还是没有什么要读取?

It depends on what 'severed' means. 这取决于“切断”的含义。

  • If you closed the socket yourself, you will get SocketException: socket closed from the various read() methods. 如果您自己关闭了套接字,则将获得SocketException: socket closed各种read()方法关闭的套接字。
  • If the connection was closed normally by the peer, all the pending data will be read before end of stream is signalled. 如果连接被对等端正常关闭,则在发出流结束信号之前,将读取所有未决数据。
  • If the connection was abortively reset, all the pending data is lost. 如果连接被异常终止重置,则所有挂起的数据都将丢失。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM