简体   繁体   中英

Getting IP address of host

I created a little game and now I am trying to make a multiplayer game out of it. One android phone should host the game and the other phone should be able to connect to this server. My question is how can I tell the Client to which IP he should connect. Is there a way to scan for hosts?

For Android games there is a perfect (and simple) library called kryonet .

It has a method - discoverHost - for scanning local network for devices that are listening for incoming connections.

Also, it contains classes such as:

that makes implementing simple communication protocol ( on both UDP and TCP protocols ) really easy.

As many people uses this library (including me) - you can find a lot of examples :

... and many others. :)

Update 1:

There is also a great library from Google called Nearby Connections API that allows to autodiscover devices in local network and allows to create multiplayer (or multiscreen) games.

Furthermore, Google has created nice (multiplatform) APIs for multiplayer games over the WAN :

Sample for Nearby Connections and Real-time Multiplayer APIs you can find here .

If I understand you correctly, you want the game host to advertise itself in the reachable network to clients to join.

There are many possibilities around this on different levels of the network protocol stack.

Somethings to look at, that come to my mind:

You see, there are quite some possibilities. Maybe you want to narrow down you question to your specific needs:

  • Who is the audience, is it a "LAN-party", other phones somewhere in the mobile space?
  • How much effort do you want to put into it?
  • What platforms do you need to support?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM