Java sockets: can I write a TCP server with one thread?

Posted by hmp on Stack Overflow See other posts from Stack Overflow or by hmp
Published on 2010-03-14T17:54:10Z Indexed on 2010/03/14 17:55 UTC
Read the original article Hit count: 171

Filed under:
|
|

From what I read about Java NIO and non-blocking [Server]SocketChannels, it should be possible to write a TCP server that sustains several connections using only one thread - I'd make a Selector that waits for all relevant channels in the server's loop.

Is that right, or am I missing some important detail? What problems can I encounter?

(Background: The TCP communication would be for a small multiplayer game, so max. 10-20 simultaneous connections. Messages will be sent about every few seconds.)

© Stack Overflow or respective owner

Related posts about java

Related posts about nio