开发者

How to find out on which internet addresses a java program can listen

开发者 https://www.devze.com 2022-12-25 17:49 出处:网络
My program needs to listen incoming socket connections (lets agree on port 8765), but it doesn\'t know which addresses it can bind on a particular machine.

My program needs to listen incoming socket connections (lets agree on port 8765), but it doesn't know which addresses it can bind on a particular machine. Of, course, it could simply to listen to all of them, but开发者_StackOverflow it need to send to the client program over a different(slower) channel the addresses which it should try in order to rich me on port 8765.

So the flow is like this:

  1. My program lisens on all available interfaces on port 8765
  2. Finds out a list of inet4 adresses by which it can be possibly reached (this step is the actual question)
  3. Posts that address on a whiteboard (blogpost or something)
  4. Interested clients try out all of them, to see using which one they can reach my program.

This is all is to be done in java ofcourse :)


NetworkInterface.getNetworkInterfaces()

0

精彩评论

暂无评论...
验证码 换一张
取 消