test/java/nio/channels/DatagramChannel/IsBound.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.

@@ -32,12 +32,14 @@
 import java.nio.channels.*;
 
 
 public class IsBound {
     public static void main(String argv[]) throws Exception {
+        try (TestUtil.UdpDayTimeServer daytimeServer =
+                        TestUtil.UdpDayTimeServer.startNewServer(100)) {
         InetSocketAddress isa = new InetSocketAddress(
-            InetAddress.getByName(TestUtil.HOST), 13);
+                    daytimeServer.getAddress(), daytimeServer.getPort());
         ByteBuffer bb = ByteBuffer.allocateDirect(256);
         bb.put("hello".getBytes());
         bb.flip();
 
         DatagramChannel dc = DatagramChannel.open();

@@ -49,6 +51,7 @@
         dc = DatagramChannel.open();
         if(dc.socket().isBound())
             throw new Exception("Test failed");
         dc.close();
     }
+    }
 }