DatagramSocket SetReuseAddress() Example
Enable/disable the SO_REUSEADDR socket option.
DatagramSocketclass 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:-20-jun-2008
*/
import java.net.*;
public class SetReuseAddress {
public static void main(String[] args) throws Exception {
DatagramSocket ds = new DatagramSocket();
ds.connect(new InetSocketAddress(9090));
//Tests if SO_REUSEADDR is enabled.
System.out.println("REUSEADDR is enabled: " + ds.getReuseAddress());
//Enable/disable the SO_REUSEADDR socket option.
ds.setReuseAddress(true);
System.out.println("REUSEADDR is enabled: " + ds.getReuseAddress());
}
} |
Output of the program:-
REUSEADDR is enabled: false
REUSEADDR is enabled: true |
|