예제 #1
0
  private void acquireMulticastLock() {
    if (null != mWifiMulticastLock && mWifiMulticastLock.isHeld()) {
      mWifiMulticastLock.release();
    }

    mWifiMulticastLock = mWifiManager.createMulticastLock(TAG);
    mWifiMulticastLock.setReferenceCounted(true);
    mWifiMulticastLock.acquire();
  }
예제 #2
0
 @Override
 public void run() {
   WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
   multicastLock = wifiManager.createMulticastLock("multicast.test");
   multicastLock.acquire();
   try {
     findServerIpAddress();
   } catch (IOException e) {
     e.printStackTrace();
   }
   multicastLock.release();
 }
예제 #3
0
  @Override
  protected void onDestroy() {
    Log.e("SDL", "onDestroy()");
    if (toastShot != null) toastShot.cancel();

    if (player != null) player.onDestroy();

    stopProgressTask();
    System.gc();

    if (multicastLock != null) {
      multicastLock.release();
      multicastLock = null;
    }
    super.onDestroy();
  }
예제 #4
0
 public static void disableMulticast() {
   if (mcLock != null) {
     mcLock.release();
   }
 }
예제 #5
0
 public static void releaseMulticastLock(final MulticastLock pMulticastLock) {
   if (pMulticastLock.isHeld()) {
     pMulticastLock.release();
   }
 }
    @Override
    protected Void doInBackground(Void... params) {
      Log.d("Discovery: ", "start UDP Server");
      String data = "0::deskcon";
      try {
        // Send "Ask for Hosts" Broadcast
        serverSocketUDP = new DatagramSocket(5108);
        serverSocketUDP.setBroadcast(true);

        InetAddress local = getBroadcast();

        // has a broadcast address been found
        if (local == null) {
          Log.d("Discovery: ", "no Broadcast Address found");
          return null;
        }

        DatagramPacket packet = new DatagramPacket(data.getBytes(), data.length(), local, 5108);
        serverSocketUDP.send(packet);

      } catch (Exception e) {
        e.printStackTrace();
        Log.d("Discovery: ", "could not start");
        return null;
      }

      WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
      MulticastLock lock = wifi.createMulticastLock("net.screenfreeze.deskcon");
      lock.acquire();

      // Receive responses from desktop hosts
      while (!isStopped) {
        byte[] receiveData = new byte[128];
        DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);

        try {
          serverSocketUDP.receive(receivePacket);
        } catch (Exception e) {
        }

        final InetAddress address = receivePacket.getAddress();

        String msg = new String(receiveData, 0, receivePacket.getLength());

        // Check for valid msg
        boolean isvalismsg = msg.split("::").length == 3;

        // Process msg if it is not our own broadcast msg
        if (!msg.equals(data) && !isStopped && isvalismsg) {

          final DesktopHost desktop = handleReceiveUdp(msg, address);
          Log.d("udp from: ", "msg " + msg + "  " + address);

          runOnUiThread(
              new Runnable() {

                @Override
                public void run() {
                  dha.add(desktop);
                }
              });
        }
      }
      lock.release();

      return null;
    }
예제 #7
0
 private void releaseMulticastLock() {
   if (null != mWifiMulticastLock && mWifiMulticastLock.isHeld()) {
     mWifiMulticastLock.release();
     mWifiMulticastLock = null;
   }
 }