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

Posted by tzador on Stack Overflow See other posts from Stack Overflow or by tzador
Published on 2010-04-02T17:03:08Z Indexed on 2010/04/02 17:13 UTC
Read the original article Hit count: 188

Filed under:
|
|
|

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 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 :)

© Stack Overflow or respective owner

Related posts about ipv4

Related posts about socket