本文整理汇总了Java中java.nio.channels.DatagramChannel.configureBlocking方法的典型用法代码示例。如果您正苦于以下问题:Java DatagramChannel.configureBlocking方法的具体用法?Java DatagramChannel.configureBlocking怎么用?Java DatagramChannel.configureBlocking使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.channels.DatagramChannel
的用法示例。
在下文中一共展示了DatagramChannel.configureBlocking方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import java.nio.channels.DatagramChannel; //导入方法依赖的package包/类
public synchronized void start() throws IOException {
if (running) {
return;
}
// Start channel
DatagramChannel channel = DatagramChannel.open();
channel.configureBlocking(true);
channel.socket().bind(new InetSocketAddress(port));
running = true;
// Start server thread
new ServerThread(channel).start();
log.info("DNS server started");
}
示例2: open
import java.nio.channels.DatagramChannel; //导入方法依赖的package包/类
@Override
protected DatagramChannel open(SocketAddress localAddress) throws Exception {
final DatagramChannel c = DatagramChannel.open();
boolean success = false;
try {
new NioDatagramSessionConfig(c).setAll(getSessionConfig());
c.configureBlocking(false);
c.socket().bind(localAddress);
c.register(selector, SelectionKey.OP_READ);
success = true;
} finally {
if (!success) {
close(c);
}
}
return c;
}
示例3: createChannel
import java.nio.channels.DatagramChannel; //导入方法依赖的package包/类
private DatagramChannel createChannel() throws IOException {
logi(TAG, "Open");
DatagramChannel datagramChannel = DatagramChannel.open();
datagramChannel.configureBlocking(false);
datagramChannel.connect(getRewrittenDestination());
return datagramChannel;
}