本文整理汇总了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;
}
}
示例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];
}
示例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;
}
示例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();
}
示例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();
}
示例6: releaseMulticastLock
import android.net.wifi.WifiManager.MulticastLock; //导入依赖的package包/类
public static void releaseMulticastLock(final MulticastLock pMulticastLock) {
if (pMulticastLock.isHeld()) {
pMulticastLock.release();
}
}