This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Simple Socket IP Address Question  RSS feed

 
Alex Birmingham
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey All -


What is the correct way to find a ServerSocket's IP address? I've tried:
1) getInetAddress() - returns 0.0.0.0/0.0.0.0
1) getLocalSocketAddress() - returns 0.0.0.0/0.0.0.0:4998

The socket is definitely bound, and working locally.


Thanks in advance.
 
Joe Ess
Bartender
Posts: 9425
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The IP address is associated with a network adapter, not a particular instance of ServerSocket. You can use ifconfig to find those addresses (ipconfig on non-Unix systems).
 
Dawn Charangat
Ranch Hand
Posts: 249
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mean the serversocket of the machine you are currently in ??? Try :

java.net.InetAddress.getLocalHost().getHostAddress()

Dawn
 
Alex Birmingham
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That did it, Dawn. Thanks!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!