0

I created an Android/Desktop game which supports multiplayer on a local area network. I am using DatagramPackets and right now I have hard coded 2 local IP addresses for testing purposes.

How do I make it so when one device is hosting a game anyone else running the game can detect that hosted game on the LAN. Basically I need to get the Local IP Address of the person who is hosting my game from another device connected to the same router searching for a game on the network.

This is how I am currently detecting the other devices on the network by hard coding the address.

outgoingPacket.setAddress(InetAddress.getByName("192.168.1.20"));

I imagine I should be using a broadcast of some sort.

CodeCamper
  • 6,609
  • 6
  • 44
  • 94
  • Something like [this solution](http://stackoverflow.com/questions/8455755/network-discovery-in-java-multicast-broadcast-java?rq=1)? – Gabriel Negut Mar 24 '15 at 17:04

2 Answers2

0

I suspect that you're looking for a more generic broadcast capability that's described here.

Multicast is a whole other kettle of fish!

Halfabee2
  • 39
  • 3
0

I think that the best way to do this is to use 1 specific port for the games, and see if someone is online on that port in the network.

tim687
  • 2,256
  • 2
  • 17
  • 28
  • What is the best way to ping if there is other games open on the network. Right now I am going to use the first broadcast address. But is this always the default broadcast address? I seem to be having a problem finding a simple code that will give me the default broadcast address. – CodeCamper Mar 24 '15 at 21:22
  • @CodeCamper what do you mean with default? The address that is actually used?? – tim687 Mar 25 '15 at 13:39
  • Exactly the address actually used. I find it strange I can't get the address that is stamped on the way out to the other local computer. I did figure out a way to do it via looping but I can't help but wonder it's not really always going to return the default address. – CodeCamper Mar 25 '15 at 18:35
  • What game engine are you using? – tim687 Mar 25 '15 at 19:04
  • Right now I am using the default Java libraries for the networking. I am using libGDX but I am making my own engine. I want to have tons of particles, fast, responsive, and little details always in sync to the best of my ability. – CodeCamper Mar 25 '15 at 19:20
  • Well, I think you'll need to knock on the door of a great android game developer to do that, I think that your plans are to optimistic – tim687 Mar 25 '15 at 19:22