Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
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  
  Local network peer discovery  (Read 4831 times)
0 Members and 1 Guest are viewing this topic.
Offline ryanm

Senior Duke


Projects: 1
Exp: 15 years


Used to be bleb


« Posted 2009-10-28 18:54:43 »

It's a class for finding other computers running the same code - useful for finding game servers etc. Can use multicast or broadcast UDP, so it probably won't reach farther than the local LAN subnet, but it beats typing in IP numbers

Code is here, JavaDoc is here. Usage looks like:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
// constructs multicast-based peer
PeerDiscovery mpd = new PeerDiscovery( multicastGroupIP, port, packetTTL );

// constructs broadcast-based peer
PeerDiscovery bpd = new PeerDiscovery( groupIP, port);

// queries the group, and waits for responses
InetAddress[] peers = peer.getPeers( timeout );

// when you're done...
peer.disconnect();


Discovery is reactive i.e.: peers listen for and respond to a query packet. In multicast mode, all traffic is multicast. In broadcast mode, the query packet is broadcast while the responses are unicast.

Multicast vs Broadcast - Distilled wisdom from the replies to this thread: Multicast is theoretically more efficient, and so may be allowed to propogate beyond the local subnet (will not go over the internet), but requires more router complexity and so is not terribly well supported. Broadcast is simple, so will work everywhere, but is unlikely to ever reach beyond the local subnet. Upshot: Use broadcast.

There's an executable jar here if you want to check the behaviour of your network.

edit: added broadcast mode, tested that it actually works, summarised thread.
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 816
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #1 - Posted 2009-10-28 18:59:48 »

NB: I haven't actually tested this for real - I've only got access to one computer at the moment.

Ah, I posted something similar here earlier, and it is tested:
http://www.java-gaming.org/topics/advertising-server-on-lan/19130/msg/150823/view.html#msg150823

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

Senior Duke


Projects: 1
Exp: 15 years


Used to be bleb


« Reply #2 - Posted 2009-10-29 10:53:27 »

Yeah, I had spotted that, but I thought I'd give multicast a try. Do you have any feeling on how well multicast is supported, as opposed to broadcast? I haven't been able to find much concrete information, just vague mutterings that multicast might at some point be allowed to reach further than the local subnet, but it isn't terribly well supported yet.
Hmmm, I might well stick some broadcasting up in this thing...
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 816
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #3 - Posted 2009-10-29 18:05:44 »

vague mutterings that multicast might at some point be allowed to reach further than the local subnet

That will cause the internets to be flooded pretty easily. Everybody would use it as an extremely cheap way of streaming video -- the routers will be swamped as they keep duplicating data every hop.


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

Senior Duke


Projects: 1
Exp: 15 years


Used to be bleb


« Reply #4 - Posted 2009-10-29 22:42:07 »

Agreed, I wasn't envisaging multicast working over the internet, just that multicast might eventually reach further than broadcast on non-domestic networks. Case in point: multicast support is planned for the network where I work, but not for a while Sad
Offline CommanderKeith
« Reply #5 - Posted 2009-10-29 23:14:00 »

I was trying to figure out what you're both talking about and found this article which helped:
http://episteme.arstechnica.com/eve/forums/a/tpc/f/469092836/m/4610971075

Still, I'm confused as to which is better for server discovery. That article makes it sounds like broadcast is better since it always goes everywhere.

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 816
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #6 - Posted 2009-10-29 23:47:01 »

In the end it doesn't really matter. Broadcast just does the job, and appearantly multicast too. Multicast should be more efficient, but that's up to the switch, which might just as well send the packet to everybody, like how a hub works. Maybe professional switches do a better job.

In the end efficiency doesn't really matter, as your server discovery traffic isn't going to saturate the network any time soon.

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

Senior Duke


Projects: 1
Exp: 15 years


Used to be bleb


« Reply #7 - Posted 2009-10-30 17:48:43 »

I've added a broadcast-UDP mode, and actually tested it now (it works!). Edits in the first post.
Offline Nate

JGO Kernel


Medals: 149
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #8 - Posted 2009-10-30 18:03:06 »

FWIW, here is my implementation:
http://code.google.com/p/kryonet/source/browse/trunk/kryonet/src/com/esotericsoftware/kryonet/Client.java#330

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 816
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #9 - Posted 2009-10-30 18:33:42 »


Offtopic:

You might know that Linus Torvald once spoke the wise words:
    'If you use more than 3 levels of indentation, you're screwed anyway.'

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

JGO Kernel


Medals: 149
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #10 - Posted 2009-10-30 21:10:52 »

Heh. Tell that to try/catch/finally. You do use Java, right? Tongue

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 816
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #11 - Posted 2009-10-30 23:00:33 »

Offtopic:

Check my network API, I rarely go beyond 3 levels (within a method body)

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

JGO Kernel


Medals: 149
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #12 - Posted 2009-10-31 15:57:15 »

Yeah. I tend to try to avoid indentation by returning, avoiding unnecessary else, etc. I usually don't bother adding methods just to avoid it though.

Offline Abuse

JGO Knight


Medals: 13


falling into the abyss of reality


« Reply #13 - Posted 2009-10-31 19:50:01 »

Everyone has widescreen 16:9, or 16:10 monitors now-a-days, so it's more like 4 levels of indent  Grin

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 816
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #14 - Posted 2009-10-31 20:32:24 »

He has 9!! Shocked

Who needs maintainability if you decide not to write bugs!

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

JGO Kernel


Medals: 149
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #15 - Posted 2009-10-31 23:10:10 »

There are more important things to worry about. More than 3 tabs certainly doesn't make code unmaintainable.

Offline Mr. Gol

Senior Duke


Medals: 1



« Reply #16 - Posted 2009-11-01 11:33:37 »

I forgot the name, but there is a metric for code complexity that uses the number of execution paths for a method. If you have 9 levels of indent, the number of possible paths becomes very high.
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.

Longarmx (38 views)
2014-10-17 03:59:02

Norakomi (28 views)
2014-10-16 15:22:06

Norakomi (24 views)
2014-10-16 15:20:20

lcass (28 views)
2014-10-15 16:18:58

TehJavaDev (53 views)
2014-10-14 00:39:48

TehJavaDev (54 views)
2014-10-14 00:35:47

TehJavaDev (43 views)
2014-10-14 00:32:37

BurntPizza (64 views)
2014-10-11 23:24:42

BurntPizza (36 views)
2014-10-11 23:10:45

BurntPizza (78 views)
2014-10-11 22:30:10
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

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!