Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (542)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (604)
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  
  NIO for networking  (Read 1780 times)
0 Members and 1 Guest are viewing this topic.
Offline thijs

Junior Devvie




Lava games rock!


« Posted 2010-11-03 09:48:19 »

Hi,

I'm about to start work on a simulation which sends its updates p2p. Depending available bandwidth a peer will have between 6 - 20 active connections.

I haven't done any tests yet, but would NIO be helpfull here? I've read mixed stories; That NIO is overly complex, that a thread per socket performs better for a small number of connections than NIO, and conversely that the memory footprint of a thread per socket adds up quickly...

Thanks!

Matthijs

<a href="http://www.dzzd.net">3DzzD!</a>
<a href="http://www.arcazoid.com">Arcazoid!</a>
Offline princec

« JGO Spiffy Duke »


Medals: 439
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #1 - Posted 2010-11-03 10:41:22 »

No, just use thread-per-peer.

Cas Smiley

Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 849
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #2 - Posted 2010-11-03 10:51:32 »

The fun thing is that, at least under Windows, regular sockets in Java are actually backed by about 12 non-blocking I/O workers. So the amount of threads is: yourThreads+min(needed, 12), even in this setup, it beats NIO by roughly 25%.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline dbotha

Senior Newbie





« Reply #3 - Posted 2010-11-03 11:32:19 »

I get the impression from you guys that NIO is not the best for networking, is this really the case? In the game I am currently working on I poll a single non blocking DatagramChannel on every gameloop update and I have yet to run into any problems. Then again I have also yet to test across a large number of different setups. What sort of issues can I expect to run into using this method?
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 849
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #4 - Posted 2010-11-03 11:35:32 »

I get the impression from you guys that NIO is not the best for networking, is this really the case? In the game I am currently working on I poll a single non blocking DatagramChannel on every gameloop update and I have yet to run into any problems. Then again I have also yet to test across a large number of different setups. What sort of issues can I expect to run into using this method?

It's slower, and harder to maintain.

Besides that, with regular I/O (blocking) you can use 1 thread for UDP too.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social
Offline princec

« JGO Spiffy Duke »


Medals: 439
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #5 - Posted 2010-11-03 11:38:14 »

NIO comms was originally designed with tens of thousands of concurrent connections in mind, where doing it thread-per-client might well lead to scalability issues. Mostly everyone actually doing server IO is only actually doing numbers in the sub-100s and therefore better off with the easier thread-per-client model of traditional IO.

Cas Smiley

Offline dbotha

Senior Newbie





« Reply #6 - Posted 2010-11-03 11:51:29 »

Thank you. Luckily the networking transport is abstracted away nicely so it shouldn't be much trouble to switch paradigms and give the thread per client model a whirl.
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 849
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #7 - Posted 2010-11-03 11:54:26 »

Thank you. Luckily the networking transport is abstracted away nicely so it shouldn't be much trouble to switch paradigms and give the thread per client model a whirl.

one connection per tcp-client, in the udp world it makes no sense.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social
Offline dbotha

Senior Newbie





« Reply #8 - Posted 2010-11-03 11:56:15 »

Sorry that's what I meant! Smiley
Offline thijs

Junior Devvie




Lava games rock!


« Reply #9 - Posted 2010-11-03 23:37:12 »

Thanks!
Confirms my doubts, with that out of the way, does anyone know a good networking (p2p) library? Ironically most of them seem to be build around NIO (and client/server for that matter). I know about JXTA, but it's way too bloated and over-engineered for my taste.

Edit: Just found this lib (http://code.google.com/p/ice4j/) which should take care of most p2p NAT traversal issues.

<a href="http://www.dzzd.net">3DzzD!</a>
<a href="http://www.arcazoid.com">Arcazoid!</a>
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline dbotha

Senior Newbie





« Reply #10 - Posted 2010-11-04 10:06:13 »

Throw in UPNP & NAT-PMP and you should get a half decent punch through success rate Smiley
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

Elsealabs (15 views)
2014-12-28 10:39:27

CopyableCougar4 (19 views)
2014-12-28 02:10:29

BurntPizza (24 views)
2014-12-27 22:38:51

Mr.CodeIt (14 views)
2014-12-27 04:03:04

TheDudeFromCI (19 views)
2014-12-27 02:14:49

Mr.CodeIt (26 views)
2014-12-23 03:34:11

rwatson462 (58 views)
2014-12-15 09:26:44

Mr.CodeIt (47 views)
2014-12-14 19:50:38

BurntPizza (96 views)
2014-12-09 22:41:13

BurntPizza (115 views)
2014-12-08 04:46:31
How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
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!