Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Java program to know in which IP server is running without joining to server and used ServerSocket class in program

  1. #1
    Junior Member
    Join Date
    Jan 2009
    Location
    uttarakhand,INDIA
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Red face Java program to know in which IP server is running without joining to server and used ServerSocket class in program

    Can anyone told me that
    how to know in which PC in lan my server is running

    -> server is started using ServerSocket class with some port number i use 8888 as port number
    -> i have a list of IP address connected to particular pc


    Now, how i would know in which IP my server is running without joining that server.


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: how to know in which PC in lan my server is running

    You could add code to your server application so it displays its current IP address?

    Try this code

    public class NetInfo {
         public static void main(String[] args) {
            new NetInfo().say();
            }
     
         public void say() {
           try {
           java.net.InetAddress i = java.net.InetAddress.getLocalHost();
           System.out.println(i);                  // name and IP address
           System.out.println(i.getHostName());    // name
           System.out.println(i.getHostAddress()); // IP address only
           }
           catch(Exception e){e.printStackTrace();}
         }
        }

    http://www.javaprogrammingforums.com...s.html#post869
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers