Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (407)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Using java.nio SocketChannel design for games  (Read 2135 times)
0 Members and 1 Guest are viewing this topic.
Offline vydias

Senior Newbie




Welcome to my world!


« Posted 2003-01-25 18:55:38 »

I've changed all of my network communications over to the new java.nio API greatly improving network speed, memory usaged and performance by using ByteBuffer and SocketChannels and ServerSocketChannels, and the new Non-blocking i/o.  

My problem is that while ServerSocketChannel connection requests allow me to process all reads and writes without using multiple threading (big improvement), I would like to get the same improvements for those players in our game that actually start the connection with a SocketChannel.  

Say we have 20 players already logged in and they all need to communicate then the last player that logged in. I will need to create SocketChannel connections to each of those 20 players.  If this is done I don't see a way to handle the reading from these channels without implementing a threaded listener on each channel. Is there a way to pool these SocketChannels like you can the ServerSocketChannel and have one thread listening for data coming from any/all of them?

None of the examples out there seem to address this issue. Without this ability I'm only able to cut my thread usage down by half rather then simply having 1 or at most 2 threads handling TCP communications for our game. Anyone have code that accomplishes all network i/o with one thread?
Offline vydias

Senior Newbie




Welcome to my world!


« Reply #1 - Posted 2003-01-25 20:26:13 »

btw this is a p2p networking paradigm so we can't have a central server for this part of our game communications. Thus I need to handle multiple SocketChannel connections when logging into the game for communications that is non-UDP capable. Meaning if I'm In TCP mode (firewalled, router non-portforwarding) or another peer is in TCP mode, direct connections must be established from the TCP mode player to the non-TCP mode player. If both parties are in TCP mode then we use a single RELAY server (all TCP players must connect to it) because direct connections can not be made between the two TCP players.

Just a little info on our networking so that people understand why we need to scale back our thread usage and why we have to use TCP connections.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars and Titan!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (94 views)
2013-05-17 21:29:12

alaslipknot (102 views)
2013-05-16 21:24:48

gouessej (132 views)
2013-05-16 00:53:38

gouessej (127 views)
2013-05-16 00:17:58

theagentd (138 views)
2013-05-15 15:01:13

theagentd (126 views)
2013-05-15 15:00:54

StreetDoggy (167 views)
2013-05-14 15:56:26

kutucuk (189 views)
2013-05-12 17:10:36

kutucuk (192 views)
2013-05-12 15:36:09

UnluckyDevil (199 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.088 seconds with 20 queries.