本文整理匯總了Java中java.nio.channels.DatagramChannel.disconnect方法的典型用法代碼示例。如果您正苦於以下問題:Java DatagramChannel.disconnect方法的具體用法?Java DatagramChannel.disconnect怎麽用?Java DatagramChannel.disconnect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.nio.channels.DatagramChannel
的用法示例。
在下文中一共展示了DatagramChannel.disconnect方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: close
import java.nio.channels.DatagramChannel; //導入方法依賴的package包/類
@Override
protected void close(DatagramChannel handle) throws Exception {
SelectionKey key = handle.keyFor(selector);
if (key != null) {
key.cancel();
}
handle.disconnect();
handle.close();
}
示例2: main
import java.nio.channels.DatagramChannel; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
InetAddress lh = InetAddress.getLocalHost();
SocketAddress remote = new InetSocketAddress(lh, 1234);
DatagramSocket ds = null;
DatagramChannel dc = null;
try {
ds = new DatagramSocket();
dc = DatagramChannel.open().bind(new InetSocketAddress(0));
check(ds, dc);
ds.connect(remote);
dc.connect(remote);
check(ds, dc);
ds.disconnect();
dc.disconnect();
check(ds, dc);
// repeat tests using socket adapter
ds.connect(remote);
dc.socket().connect(remote);
check(ds, dc);
ds.disconnect();
dc.socket().disconnect();
check(ds, dc);
} finally {
if (ds != null) ds.close();
if (dc != null) dc.close();
}
}
示例3: close
import java.nio.channels.DatagramChannel; //導入方法依賴的package包/類
@Override
protected void close(DatagramChannel handle) throws Exception {
handle.disconnect();
handle.close();
}