test/java/nio/channels/SocketChannel/LocalAddress.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2002, 2010, 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. --- 1,7 ---- /* ! * Copyright (c) 2002, 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,47 **** * @summary Test getLocalAddress getLocalPort * @library .. */ import java.net.*; - import java.nio.*; import java.nio.channels.*; public class LocalAddress { public static void main(String[] args) throws Exception { ! test1(); } ! static void test1() throws Exception { InetAddress bogus = InetAddress.getByName("0.0.0.0"); InetSocketAddress saddr = new InetSocketAddress( ! InetAddress.getByName(TestUtil.HOST), 23); //Test1: connect only SocketChannel sc = SocketChannel.open(); try { sc.connect(saddr); --- 26,51 ---- * @summary Test getLocalAddress getLocalPort * @library .. */ import java.net.*; import java.nio.channels.*; public class LocalAddress { public static void main(String[] args) throws Exception { ! // We use an EchoServer rather than a Telnet server here - but hopefully ! // it doesn't matter for the test purposes. ! try (TestUtil.EchoServer echoServer = ! TestUtil.EchoServer.startNewServer()) { ! test1(echoServer); ! } } ! static void test1(TestUtil.AbstractServer server) throws Exception { InetAddress bogus = InetAddress.getByName("0.0.0.0"); InetSocketAddress saddr = new InetSocketAddress( ! server.getAddress(), server.getPort()); //Test1: connect only SocketChannel sc = SocketChannel.open(); try { sc.connect(saddr);