简体   繁体   中英

Wifi Game Detect Servers in Local Area Network

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.

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

Multicast is a whole other kettle of fish!

我认为最好的方法是为游戏使用1个特定端口,并查看网络中该端口是否有人在线。

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