File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Is it possible to read data after nio socket channel closed? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Reply locked New topic
Author

Is it possible to read data after nio socket channel closed?

Harvinder Thakur
Ranch Hand

Joined: Jun 10, 2008
Posts: 231
I am also posting my question in this forum in hope of getting more responses.

I have an NIO Socket Server "S1".
I have an NIO Socket Client thread T1 having reference to a valid socket channel connected to "S1"

S1 sends messages to T1 say of 100 bytes each in an infinite loop.

T1 runs in an infinite loop & has a read() method which reads from the socket channel when the Selector registered with it receives an OP_READ key. After each successful read thread T1 sleeps for 5 seconds.

Here are some questions looking to be answered:

1.) What happens to the messages sent by S1 when thread T1 is sleeping ?

2.) Does the Selector registered with the Socket Channel buffer the messages irrespective of the fact that T1 is sleeping ?

3.) If answer to 2.) is YES then what happens when Server S1 has sent say 500 bytes while T1 was sleeping and then S1 disconnects due to some IOException before T1 wakes up. Have those 500 bytes sent by S1 before disconnecting been received and buffered by the Selector?
If they have been received and buffered then is it possible to retrieve them?

Any help is appreciated.


thanks
Harvinder
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8705
    
    6

Harvinder Thakur wrote:I am also posting my question in this forum in hope of getting more responses.
.


Please do not post the same question more than once. Your original question is in the correct forum. If no one answers your question, it may be because NIO is the "road less traveled" and not many people have in-depth experience with it.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Is it possible to read data after nio socket channel closed?
 
Similar Threads
Catching Socket Exceptions
nio and file transfers
Please verify if i understand NIO Selectors
Two threads, one socket
does a nio socket buffer data internally too?