本文整理匯總了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;
}