Therefore, each port's main-service-thread (the one that a posted earlier) should have to make a new thread for each connected client so that it can serve even more clients, right? And it's when I do this, that the the SocketChannels decide to die on me
!!! (blahblahblah thinks: "I take it you mean "Socket"'s here, not SocketChannel's, since the latter ONLY work with NIO.", and then realises he misread the original code).
You ARE using NIO. This may be why it's not working as you expect
. When you mentioned the Sun tutorial (I haven't yet read any Sun tutorials for NIO) I think a combination of too much work, too little sleep helped me misread your post to think you were using thread-per-connection, and old-IO.
The typical way with IO is to
- Socket blah = serversocket.accept();
- Create a new object to handle that socket (usually using "new")
- ...either pass the object the Socket, or more often just use the Socket as one of the arguments to the constructor...
- call start() on the object ( which normally is a method that looks like this:
public void start()
Thread t = new Thread( this );
...and of course your object must have a "public void run()" method, as defined by the Runnable interface.
Note that anything with the word "Channel" in it means, automatically, that you are using NIO. Apologies for me confusing the issue
- can you copy/paste the URL of the particular Sun tutorial you were following? I didn't realise there were any NIO tuts from Sun yet...
About nio - I honestly don't know enough about it - YET
If you have some good examples / links / tutorials I'm all ears!
I suggest you read through those three articles, and you may find you understand NIO enough to use it (I've had a couple of emails from people who said that) - HOWEVER, they aren't complete, and have lots of bits I've changed in the latest revision (not available yet), so you may well still not quite know what to do.
The updated version will appear on JGO.org (this site) - *nudge* ChrisM
- but until then you can use the link above which is OK (just not as up to date nor as detailed).