当前位置: 首页>>代码示例>>Java>>正文


Java MulticastLock.setReferenceCounted方法代码示例

本文整理汇总了Java中android.net.wifi.WifiManager.MulticastLock.setReferenceCounted方法的典型用法代码示例。如果您正苦于以下问题:Java MulticastLock.setReferenceCounted方法的具体用法?Java MulticastLock.setReferenceCounted怎么用?Java MulticastLock.setReferenceCounted使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.net.wifi.WifiManager.MulticastLock的用法示例。


在下文中一共展示了MulticastLock.setReferenceCounted方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: multicast

import android.net.wifi.WifiManager.MulticastLock; //导入方法依赖的package包/类
/**
 * 
 * @param multicastIP for example, 224.X.X.X or 239.X.X.X
 * @param port
 * @param bs
 */
public static void multicast(final String multicastIP, final int port, final byte[] sendData){
	final WifiManager wifi = getWiFiManager();
	MulticastLock multicastLock = wifi.createMulticastLock(String.valueOf(System.currentTimeMillis()));
	multicastLock.setReferenceCounted(true);
	multicastLock.acquire();
	
	try{
		final MulticastSocket multicastSocket=new MulticastSocket(port);
        multicastSocket.setLoopbackMode(true);
        final InetAddress group = InetAddress.getByName(multicastIP);
        multicastSocket.joinGroup(group);
        
        final DatagramPacket packet=new DatagramPacket(sendData, sendData.length,group,port);
        
           multicastSocket.send(packet);
	}catch (final Throwable e) {
		e.printStackTrace();
	}
	
	if (multicastLock != null) {
	    multicastLock.release();
	    multicastLock = null;
	}
}
 
开发者ID:javalovercn,项目名称:j2se_for_android,代码行数:31,代码来源:HCWiFiManager.java

示例2: discoverService

import android.net.wifi.WifiManager.MulticastLock; //导入方法依赖的package包/类
public static ServiceInfo discoverService(String service, int timeOut, Context context) throws IOException
{
	StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
	StrictMode.setThreadPolicy(policy);
	
	WifiManager manager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
	WifiInfo wifiInfo = manager.getConnectionInfo();
	
	int intaddr = wifiInfo.getIpAddress();
	byte[] byteaddr = new byte[] { (byte) (intaddr & 0xff), (byte) (intaddr >> 8 & 0xff), (byte) (intaddr >> 16 & 0xff), (byte) (intaddr >> 24 & 0xff) };
	InetAddress addr=InetAddress.getByAddress(byteaddr);
    String hostname = InetAddress.getByName(addr.getHostName()).toString();
	
    MulticastLock lock = manager.createMulticastLock("mpdcontrol_bonjour");
       lock.setReferenceCounted(true);
       lock.acquire();
       JmDNS jmdns = JmDNS.create(addr, hostname);
	
       ServiceInfo[] infos = {};
	infos = jmdns.list(service, timeOut);
			
	jmdns.close();
	
	if (infos.length == 0) return null;
	return infos[0];
}
 
开发者ID:thunderace,项目名称:mpd-control,代码行数:27,代码来源:ServiceBonjour.java

示例3: aquireMulticastLock

import android.net.wifi.WifiManager.MulticastLock; //导入方法依赖的package包/类
public static MulticastLock aquireMulticastLock(final Context pContext, final String pMulticastLockName) {
	final WifiManager wifiManager = WifiUtils.getWifiManager(pContext);
	final MulticastLock multicastLock = wifiManager.createMulticastLock(pMulticastLockName);
	multicastLock.setReferenceCounted(true);
	multicastLock.acquire();
	return multicastLock;
}
 
开发者ID:ArturVasilov,项目名称:AndroidCourses,代码行数:8,代码来源:WifiUtils.java


注:本文中的android.net.wifi.WifiManager.MulticastLock.setReferenceCounted方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。