本文整理汇总了Java中java.net.MulticastSocket.setBroadcast方法的典型用法代码示例。如果您正苦于以下问题:Java MulticastSocket.setBroadcast方法的具体用法?Java MulticastSocket.setBroadcast怎么用?Java MulticastSocket.setBroadcast使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.net.MulticastSocket
的用法示例。
在下文中一共展示了MulticastSocket.setBroadcast方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onResume
import java.net.MulticastSocket; //导入方法依赖的package包/类
@Override
protected void onResume() {
super.onResume();
fileReciveThread = new FileReciveThread();
fileReciveThread.start();
try {
socket = new MulticastSocket(portNum);
socket.setInterface(ip);
socket.setBroadcast(true);
group = InetAddress.getByName("224.0.0.1");
socket.joinGroup(new InetSocketAddress(group, portNum), networkInterface);
} catch (IOException e) {
e.printStackTrace();
}
}
示例2: OioDatagramChannel
import java.net.MulticastSocket; //导入方法依赖的package包/类
/**
* Create a new instance from the given {@link MulticastSocket}.
*
* @param socket the {@link MulticastSocket} which is used by this instance
*/
public OioDatagramChannel(MulticastSocket socket) {
super(null);
boolean success = false;
try {
socket.setSoTimeout(SO_TIMEOUT);
socket.setBroadcast(false);
success = true;
} catch (SocketException e) {
throw new ChannelException(
"Failed to configure the datagram socket timeout.", e);
} finally {
if (!success) {
socket.close();
}
}
this.socket = socket;
config = new DefaultDatagramChannelConfig(this, socket);
}
示例3: setUpSocket
import java.net.MulticastSocket; //导入方法依赖的package包/类
private static MulticastSocket setUpSocket() throws IOException {
MulticastSocket recSocket = new MulticastSocket(null);
recSocket.bind(new InetSocketAddress(InetAddress.getByName("0.0.0.0"), PORT));
recSocket.setTimeToLive(10);
recSocket.setSoTimeout(1000);
recSocket.setBroadcast(true);
return recSocket;
}
示例4: createSocket
import java.net.MulticastSocket; //导入方法依赖的package包/类
protected DatagramSocket createSocket() throws IOException {
MulticastSocket s = new MulticastSocket();
s.setSendBufferSize(maxTraceDatagramSize);
s.setBroadcast(broadcast);
s.setLoopbackMode(true);
s.setTimeToLive(timeToLive);
return s;
}