test/java/nio/channels/SocketChannel/Basic.java
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2000, 2001, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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.
@@ -34,17 +34,13 @@
public class Basic {
static java.io.PrintStream out = System.out;
- static final int DAYTIME_PORT = 13;
- static final String DAYTIME_HOST = TestUtil.HOST;
-
- static void test() throws Exception {
- InetSocketAddress isa
- = new InetSocketAddress(InetAddress.getByName(DAYTIME_HOST),
- DAYTIME_PORT);
+ static void test(TestUtil.DayTimeServer daytimeServer) throws Exception {
+ InetSocketAddress isa = new InetSocketAddress(daytimeServer.getAddress(),
+ daytimeServer.getPort());
SocketChannel sc = SocketChannel.open(isa);
out.println("opened: " + sc);
/*
out.println("opts: " + sc.options());
((SocketOpts.IP.TCP)sc.options())
@@ -74,9 +70,12 @@
sc.close();
out.println("closed: " + sc);
}
public static void main(String[] args) throws Exception {
- test();
+ try (TestUtil.DayTimeServer dayTimeServer =
+ TestUtil.DayTimeServer.startNewServer(100)) {
+ test(dayTimeServer);
+ }
}
}