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


Java MulticastLock类代码示例

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


MulticastLock类属于android.net.wifi.WifiManager包,在下文中一共展示了MulticastLock类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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

示例4: R2RNet

import android.net.wifi.WifiManager.MulticastLock; //导入依赖的package包/类
public R2RNet( RocrailService rocrailService, Preferences Prefs ) {
  this.Prefs = Prefs;  

  WifiManager wifi = (WifiManager) rocrailService.getSystemService(Context.WIFI_SERVICE);
  MulticastLock lock = wifi.createMulticastLock("r2rlock");
  lock.acquire();
}
 
开发者ID:prashant31191,项目名称:andRoc,代码行数:8,代码来源:R2RNet.java

示例5: startThread

import android.net.wifi.WifiManager.MulticastLock; //导入依赖的package包/类
private void startThread() {
	thread = new Thread() {
		public void run() {
			WifiManager wim = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
			if (wim != null) {
				MulticastLock mcLock = wim.createMulticastLock(Globals.TAG);
				mcLock.acquire();
			}
			byte[] buffer = new byte[Globals.BUFFER_SIZE];
			DatagramPacket rPacket = new DatagramPacket(buffer, buffer.length);
			MulticastSocket rSocket;
			try {
				rSocket = new MulticastSocket(Globals.PORT);
			} catch (IOException e) {
				Log.d("MessageReceiver", "Impossible to create a new MulticastSocket on port " + Globals.PORT);
				e.printStackTrace();
				return;
			}

			while (!isInterrupted()) {
				Log.d("MessageReceiver", "Waiting for Messages...");
				try {
					rSocket.receive(rPacket);
				} catch (IOException e1) {
					Log.d("MessageReceiver", "There was a problem receiving the incoming message.");
					continue;
				}
				if (isInterrupted())
					break;
				Log.d("MessageReceiver", "Received Message! Processing...");
				byte data[] = rPacket.getData();
				try {
					msgQueue.add(Message.deserialize(data));
				} catch (IllegalArgumentException ex) {
					Log.d("MessageReceiver", "There was a problem processing the message " + Arrays.toString(data));
					continue;
				}
				handler.post(processRunnable);
			}
			rSocket.close();
		}
	};
	thread.start();
}
 
开发者ID:dks-rub,项目名称:meshchat,代码行数:45,代码来源:MessageReceiver.java

示例6: releaseMulticastLock

import android.net.wifi.WifiManager.MulticastLock; //导入依赖的package包/类
public static void releaseMulticastLock(final MulticastLock pMulticastLock) {
	if (pMulticastLock.isHeld()) {
		pMulticastLock.release();
	}
}
 
开发者ID:ArturVasilov,项目名称:AndroidCourses,代码行数:6,代码来源:WifiUtils.java


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