• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Accessing IP Address of Remote computer

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can I access another computer IP address from my computer in network.I have writen this code. But this is displaying only LocalHost IP address.



import java.net.*;

class InetAddressTest{

public static void main(String args[]) throws Exception{

InetAddress add=InetAddress.getLocalHost();
System.out.println(add);

ServerSocket sersoc =new ServerSocket(1000);
Socket socket = sersoc.accept ();
System.out.println ("Client from " + socket.getInetAddress().getHostAddress());

}
}
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What did you expect?
You're printing your the address of localhost which is always 127.0.0.1
Then you wait for another computer to connect to you.
 
reply
    Bookmark Topic Watch Topic
  • New Topic