Online Java Compiler By
JavaTpoint.com
import java.io.IOException; import java.net.*; public class JavaSocketSetReuseAddressExample3 { public static void main(String[] args) throws IOException { //calling the constructor of the socket class Socket socket = new Socket(); //closing the socket socket.close(); //enabling the SO_REUSEADDR option Boolean on=false; //setReuseAddress() method enables or disables the SO_REUSEADDR option //it will throw an exception, as the socket is already closed socket.setReuseAddress(on); //getReuseAddress() method returns boolean value 'true' if SO_REUSEADDR option is enabled else it return false if(socket.getReuseAddress()){ System.out.println("SO_REUSEADDR option is enabled"); } else{ System.out.println("SO_REUSEADDR option is disabled"); } } }
Output