DatagramSocket SetBroadcast() Example
Enable/disable SO_BROADCAST.
DatagramSocketclass SetBroadcast() method example. This example shows you how to use SetBroadcast() method.This method Enable/disable SO_BROADCAST.
Here is the code:-
/**
* @Program that Enable/disable SO_BROADCAST.
* SetBroadcast.java
* Author:-RoseIndia Team
* Date:-20-jun-2008
*/
import java.net.*;
public class SetBroadcast {
public static void main(String[] args) throws Exception {
DatagramSocket ds = new DatagramSocket();
ds.connect(new InetSocketAddress(9090));
//Tests if SO_BROADCAST is enabled.
System.out.println(" SO_BROADCAST is enabled: " + ds.getBroadcast());
// Enable/disable SO_BROADCAST.
ds.setBroadcast(false);
System.out.println(" SO_BROADCAST is enabled: " + ds.getBroadcast());
}
} |
Output of the program:-
SO_BROADCAST is enabled: true
SO_BROADCAST is enabled: false |
|