ServerSocket GetLocalSocketAddress() Example

Started by VelMurugan, Jan 06, 2009, 07:58 AM

Previous topic - Next topic

VelMurugan

ServerSocket GetLocalSocketAddress() Example

Returns the address of the endpoint this socket is bound to, or null if it is not bound yet.

ServerSocketclass GetLocalSocketAddress() method example. This example shows you how to use GetLocalSocketAddress() method.This method Returns the address of the endpoint this socket is bound to, or null if it is not bound yet.

Here is the code:-

/**
* @Program that  Returns the address of the endpoint this socket is bound to,
* or null if it is not bound yet.
* GetLocalSocketAddress.java
* Author:-RoseIndia Team
* Date:-21-jun-2008
*/
import java.net.*;

public class GetLocalSocketAddress {

    public static void main(String[] args) throws Exception {
        InetAddress i = InetAddress.getByName("girish-desktop");
        ServerSocket ss = new ServerSocket(8080, 1, i);
        //Returns the address of the endpoint this socket is bound to
        System.out.println("Address of the endpoint this socket is bound to is: " + ss.getLocalSocketAddress());
    }
}


Output of the program:-

Address of the endpoint this socket is bound to is: girish-desktop/127.0.1.1:8080

Source : codingdiary