java - why the TCP receiver can receive data after the Socket Server has shut down? -


i using java implement multithreaded tcp server-client application. have encountered strange problem: when shutdown server socket, receiver can still receives last sent packet continuously. since detail of socket read of kernel concern, can't figure out reason. can give guideline? in advance! edit: code involved simple:

public void run() {   while(runflag) {       //in = socket.getsocketinputstream();       //byte[] buffer = new byte[buffersize];        try {           in.read(buffer);           //process buffer;       }catch(ioexception e) {           //       }   } } 

when shutdown server socket, read operation receive packet continuously(each time enters while loop).

the tcp/ip stack inside os buffering data on both sides of connection. sender fills socket send buffer, drained device driver pushing packets onto wire. receiver accumulates packets off wire in socket receive buffer, drained application reads.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -