下面列出了java.nio.channels.DatagramChannel#disconnect() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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();
}
}
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();
}
}
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();
}
}
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();
}
}
@Override
protected void close(DatagramChannel handle) throws Exception {
SelectionKey key = handle.keyFor(selector);
if (key != null) {
key.cancel();
}
handle.disconnect();
handle.close();
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
@Override
protected void close(DatagramChannel handle) throws Exception {
handle.disconnect();
handle.close();
}