• Advertisement
Sign in to follow this  

[java] Creating a server with channels

This topic is 3738 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Title says it all. I'm a bit perplexed as to how I am going to accomplish this. I had envisioned it kind of like this: GameServer class contains an array of Channel classes which contain an array of Connections. Connections extend thread. However, it seems I can't have an array of Threads (I get a "can not cast from void to Connection" error) which is really odd...is there another way to go about this?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by MLC
Title says it all. I'm a bit perplexed as to how I am going to accomplish this. I had envisioned it kind of like this:

GameServer class contains an array of Channel classes which contain an array of Connections. Connections extend thread.


No, no, no :) The java.nio package was added to the API in order to avoid the need to create one thread per client connection, which was the only way to handle things when using java.net. But the thread-per-client model is ultimately an inefficient, non-scalable design. So you certainly don't want your Connection class to extend Thread.

There's a bit much to it to layout in a forum post for someone who isn't familiar with the topic, so I'll point you to some useful resources. This PDF is a great introduction to the java.nio package in general. Chapter 9 deals with the networking components specifically. That should cover most of what you need to know to get started, but it's always good to hit multiple sources of information for expanded points of view when learning something like this. I'd recommend the Rox Java NIO Tutorial and this IBM developerworks article (the latter requires free registration, but it's worth it as there are a lot of good articles at IBM developerworks).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement