ServerSocket SetReuseAddress() Example

Enable/disable the SO_REUSEADDR socket option.


ServerSocketclass SetReuseAddress() method example. This example shows you how to use SetReuseAddress() method.This method Enable/disable the SO_REUSEADDR socket option.

Here is the code:-

/**
 * @Program that Enable/disable the SO_REUSEADDR socket option.
 * SetReuseAddress.java 
 * Author:-RoseIndia Team
 * Date:-21-jun-2008
 */
import java.net.*;

public class SetReuseAddress {

    public static void main(String[] argsthrows Exception {
        InetAddress i = InetAddress.getByName("girish-desktop");
        ServerSocket ss = new ServerSocket(80801, i);
        //Tests if SO_REUSEADDR is enabled.
        System.out.println("SO_REUSEADDR is enabled: " + ss.getReuseAddress());
        // Enable/disable the SO_REUSEADDR socket option.
        ss.setReuseAddress(false);
        System.out.println("SO_REUSEADDR is enabled: " + ss.getReuseAddress());
    }
}

Output of the program:-
 SO_REUSEADDR is enabled: true
SO_REUSEADDR is enabled: false

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US