Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NIO: Registering Socket with selector

Status
Not open for further replies.

zoomby

Programmer
Aug 5, 2002
60
0
0
DE
Hi!
Here's the situation:
I created a simple server using NIO that sends data to the client.
I write some data to the client socket and then cancel the SelectionKey, so that no more "ready to write" events occur with this socket, but the socket still is connected.
The problem is that I don't know how to register the socket with the selector again. I tried to do that (The server loop is in one thread, and I tried to register the socket from the main thread) but the main thread even blocked.
Can anyone help me to solve the problem?

bye
Chris
 
>> but the main thread even blocked.

post the code where it blocks

-pete
 
hi,
I know a little bit more now. It's the select() method from the selector which blocks (of course). That's natural, but I don't have a chance to register a socket with this selector from another thread while it blocks. I tried to wakeup() the selector befor registering a socket but that doesn't help.
Is there any way to do that?

bye
Chris
 
>> but I don't have a chance to register a socket with this selector from another thread

With NIO you should do all your select() calls in a single thread that is designed (in your application) for handling the socket IO. Don’t use multiple threads with NIO.

-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top