简体   繁体   中英

Java. How to get a list of exactly my servers in the local network?

Using tcp sockets, I wrote a server, launched it on a computer. Wrote a client for android. Being in the same local.network, I successfully connect from my smartphone knowing the local ip address of the computer and the server port.

The problem is that I want to run this server on multiple computers on the local.network, and their local addresses can change.

Need to somehow scan and select an available server in the application.

How is it implemented? What is the special protocol for scanning? Or just try to connect by sorting through all possible addresses and ports?

Is UDP broadcast a bad solution?

Sorry for google-translator!

UPD: I am trying to make a remote PC application. This will not work on the global inte.net. only local.network. Thanks for the answer

I solve it by use DatagramSocket to UDP broadcast to 192.168.1.255.

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