English 中文(简体)
为什么TCP接收器在Socket服务器关闭后能够接收数据?
原标题:why the TCP receiver can receive data after the Socket Server has shut down?

I am using Java to implement a multithreaded TCP server-client application. But now i have encountered a strange problem: when i shutdown the server socket, the receiver can still receives the last sent packet continuously. Since the detail of socket read is of the kernel concern, i can t figure out the reason. Can anybody give some guideline? Thanks in advance! Edit: The code involved is simple:

public void run() {
  while(runFlag) {
      //in = socket.getSocketInputStream();
      //byte[] buffer = new byte[bufferSize]; 
      try {
          in.read(buffer);
          //process the buffer;
      }catch(IOException e) {
          //
      }
  }
}

在关闭服务器单时,这一读机将不断接收包装(每次进入时)。

问题回答

The TCP/IP sack within the OS is buffering the data on both parties of the connection. 放电器填充其的袖珍/em>,由把包装包推到电线上的司机耗尽。 接收器在的电线上积累了包装,并收到缓冲<>/em>,该电线因申请而流失。

如果数据已经放在客户的袖珍中(在座机上,等待您将其应用到用户空间记忆中),那么服务器便无法读到数据。 它像天花邮件一样:一旦你寄出,你就无法打消。

这使TCP是如何运作的。 它是可靠的下游。 未交付的数据继续在正常关闭后提供。 难道不是你们想要的吗? 为什么这是一个问题?





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...