Code example for DatagramSocket

Methods: setBroadcast

0
      Handler handler) {
    mBroadcastAddress = broadcastAddress;
    mHandler = handler;
 
    try { 
      mSocket = new DatagramSocket(); // binds to random port
      mSocket.setBroadcast(true);
    } catch (SocketException e) {
      Log.e(LOG_TAG, "Could not create broadcast client socket.", e);
      throw new RuntimeException();
    } 
 
    mProbeTimer = new Timer();
    mProbeTimerTask = new TimerTask() {
      @Override 
      public void run() { 
        BroadcastDiscoveryClient.this.sendProbe();
      } 
    }; 
    Log.i(LOG_TAG, "Starting client on address " + mBroadcastAddress);
  }