PDA

View Full Version : New Java IO (java.nio.*)



Nemesis
09-27-2004, 04:33 AM
This motivation of this question is not exactly indie game related.. but if anyone is working on a Java game and has had to deal with networking code, I'm hoping to get some insights. The main reason I'm researching NIO is that it allows unblocked socket accept calls and socket reads and writes. That means I can write server code without the need to have a separate thread for every listener (I am listening on two different ports), and a separate thread for each and every connection.

Can anyone please offer his/her experience on NIO and how it compares to traditional stream-based socket programming?

princec
09-27-2004, 05:31 AM
It's largely simpler and easier to understand but be aware it was somewhat "broken" before 1.4.2 for any serious work, except with respect to interfacing with OpenGL.

Cas :)

Nemesis
09-27-2004, 12:32 PM
Well.. apparently even the old java.net.* classes are now implemented using java.nio.* so i'm assuming that the API is relatively stable. Anyway.. I'll soon find out! :) Seriously.. I do think that the server code will run better because I'm planning to use few, if any, worker threads.

princec
09-27-2004, 01:40 PM
Ideally your server game loop will consist of one extremely busy thread and not much else.

Cas :)

Nemesis
09-27-2004, 02:08 PM
It's an app loop rather than a game loop to be precise.. some stuff I'm doing in my day job. I still think the same concepts apply.. better one busy thread than several idle ones that hog down the processor with context switching etc.