test/java/nio/channels/DatagramChannel/IsConnected.java
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
@@ -26,23 +26,25 @@
* @summary Simple test of DatagramSocket connection consistency
* @library ..
*/
import java.net.*;
-import java.nio.*;
import java.nio.channels.*;
public class IsConnected {
public static void main(String argv[]) throws Exception {
+ try (TestClass.UdpDayTimeServer daytimeServer
+ = TestClass.UdpDayTimeServer.startNewServer(100)) {
InetSocketAddress isa = new InetSocketAddress(
- InetAddress.getByName(TestUtil.HOST), 13);
+ daytimeServer.getAddress(), daytimeServer.getPort());
DatagramChannel dc = DatagramChannel.open();
dc.configureBlocking(true);
dc.connect(isa);
if (!dc.isConnected())
throw new RuntimeException("channel.isConnected inconsistent");
if (!dc.socket().isConnected())
throw new RuntimeException("socket.isConnected inconsistent");
dc.close();
}
+ }
}