private void acquireMulticastLock() { if (null != mWifiMulticastLock && mWifiMulticastLock.isHeld()) { mWifiMulticastLock.release(); } mWifiMulticastLock = mWifiManager.createMulticastLock(TAG); mWifiMulticastLock.setReferenceCounted(true); mWifiMulticastLock.acquire(); }
@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(); }
@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(); }
public static void disableMulticast() { if (mcLock != null) { mcLock.release(); } }
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; }
private void releaseMulticastLock() { if (null != mWifiMulticastLock && mWifiMulticastLock.isHeld()) { mWifiMulticastLock.release(); mWifiMulticastLock = null; } }