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:
- My program lisens on all available interfaces on port 8765
- Finds out a list of inet4 adresses by which it can be possibly reached (this step is the actual question)
- Posts that address on a whiteboard (blogpost or something)
- 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()
精彩评论