jdk/test/java/net/ipv6tests/TcpTest.java
author chegar
Tue, 16 Mar 2010 10:05:51 +0000
changeset 5151 e62028f44cf6
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6934923: test/java/net/ipv6tests/TcpTest.java hangs on Solaris 10 Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2003 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 4868820
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary IPv6 support for Windows XP and 2003 server
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.net.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
public class TcpTest extends Tests {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
    static ServerSocket server, server1, server2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
    static Socket c1, c2, c3, s1, s2, s3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    static InetAddress s1peer, s2peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    static InetAddress ia4any;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    static InetAddress ia6any;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    static Inet6Address ia6addr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    static InetAddress ia6bad; /* a global 6to4 IPv6 address, which cant be connected to */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    static Inet4Address ia4addr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        ia6addr = getFirstLocalIPv6Address ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        ia4addr = getFirstLocalIPv4Address ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
            ia4any = InetAddress.getByName ("0.0.0.0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
            ia6any = InetAddress.getByName ("::0");
5151
e62028f44cf6 6934923: test/java/net/ipv6tests/TcpTest.java hangs on Solaris 10
chegar
parents: 2
diff changeset
    50
            if (ia6addr != null) {
e62028f44cf6 6934923: test/java/net/ipv6tests/TcpTest.java hangs on Solaris 10
chegar
parents: 2
diff changeset
    51
                int scope = ia6addr.getScopeId();
e62028f44cf6 6934923: test/java/net/ipv6tests/TcpTest.java hangs on Solaris 10
chegar
parents: 2
diff changeset
    52
                if (scope != 0) {
e62028f44cf6 6934923: test/java/net/ipv6tests/TcpTest.java hangs on Solaris 10
chegar
parents: 2
diff changeset
    53
                    ia6bad = InetAddress.getByName ("fe80::1:2:3:4:5:6%"+scope);
e62028f44cf6 6934923: test/java/net/ipv6tests/TcpTest.java hangs on Solaris 10
chegar
parents: 2
diff changeset
    54
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
                ia6bad = InetAddress.getByName ("fe80::1:2:3:4:5:6");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public static void main (String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        checkDebug(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        if (ia6addr == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            System.out.println ("No IPV6 addresses: exiting test");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        dprintln ("Local Addresses");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        dprintln (ia4addr.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        dprintln (ia6addr.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        dprintln ("Bad address: " + ia6bad);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        test1 (0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        test1 (5100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        test2();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        test3();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        test4();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    /* basic TCP connectivity test using IPv6 only and IPv4/IPv6 together */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    static void test1 (int port) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        server = new ServerSocket (port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        if (port == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            port = server.getLocalPort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        // try Ipv6 only
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        c1 = new Socket ("::1", port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        s1 = server.accept ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        simpleDataExchange (c1, s1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        s1.close ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        c1.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        // try with both IPv4 and Ipv6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        c1 = new Socket ("127.0.0.1", port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        c2 = new Socket ("::1", port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        s1 = server.accept();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        s2 = server.accept();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        s1peer = s1.getInetAddress();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        s2peer = s2.getInetAddress();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        if (s1peer instanceof Inet6Address) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            t_assert ((s2peer instanceof Inet4Address));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            simpleDataExchange (c2, s1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            simpleDataExchange (c1, s2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            t_assert ((s2peer instanceof Inet6Address));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            simpleDataExchange (c1, s1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            simpleDataExchange (c2, s2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        c1.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        c2.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        s1.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        s2.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        server.close ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        System.out.println ("Test1: OK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /** bind tests:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     *  1. bind to specific address IPv4 only (any port)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *  2. bind to specific address IPv6 only (any port)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     *  3. bind to specific address IPv4 only (specific port)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *  4. bind to specific address IPv4 only (specific port)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *  5. bind to any address IPv4 (test collision)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    static void test2 () throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        server = new ServerSocket ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        InetSocketAddress sadr = new InetSocketAddress (ia4addr, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        server.bind (sadr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        dprintln ("server bound to " + sadr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        int port = server.getLocalPort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        InetSocketAddress sadr6 = new InetSocketAddress (ia6addr, port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        c1 = new Socket (ia4addr, port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            dprintln ("connecting to " + ia6addr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            c2 = new Socket ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            c2.connect (sadr6, 1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            throw new RuntimeException ("connect to IPv6 address should be refused");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        } catch (IOException e) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        server.close ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        c1.close ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        /* now try IPv6 only */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        server = new ServerSocket ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        sadr = new InetSocketAddress (ia6addr, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        dprintln ("binding to " + sadr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        server.bind (sadr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        port = server.getLocalPort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        c1 = new Socket (ia6addr, port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            c2 = new Socket (ia4addr, port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            throw new RuntimeException ("connect to IPv4 address should be refused");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        } catch (IOException e) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        server.close ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        c1.close ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        /* now try IPv6 specific port only */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        server = new ServerSocket ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        sadr = new InetSocketAddress (ia6addr, 5200);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        server.bind (sadr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        port = server.getLocalPort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        t_assert (port == 5200);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        c1 = new Socket (ia6addr, port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            c2 = new Socket (ia4addr, port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            throw new RuntimeException ("connect to IPv4 address should be refused");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        } catch (IOException e) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        server.close ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        c1.close ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        /* now try IPv4 specific port only */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        server = new ServerSocket ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        sadr = new InetSocketAddress (ia4addr, 5200);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        server.bind (sadr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        port = server.getLocalPort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        t_assert (port == 5200);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        c1 = new Socket (ia4addr, port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            c2 = new Socket (ia6addr, port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            throw new RuntimeException ("connect to IPv6 address should be refused");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        } catch (IOException e) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        server.accept().close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        c1.close ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        server.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        System.out.println ("Test2: OK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    /* Test timeouts on accept(), connect() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    static void test3 () throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        server = new ServerSocket (0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        server.setSoTimeout (5000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        int port = server.getLocalPort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        long t1 = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            server.accept ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            throw new RuntimeException ("accept should not have returned");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        } catch (SocketTimeoutException e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        t1 = System.currentTimeMillis() - t1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        checkTime (t1, 5000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        c1 = new Socket ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        c1.connect (new InetSocketAddress (ia4addr, port), 1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        s1 = server.accept ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        simpleDataExchange (c1,s1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        c2 = new Socket ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        c2.connect (new InetSocketAddress (ia6addr, port), 1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        s2 = server.accept ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        simpleDataExchange (c2,s2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        c3 = new Socket ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        c3.connect (new InetSocketAddress (ia6addr, port), 1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        s3 = server.accept ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        c2.close (); s2.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        server.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        simpleDataExchange (c3,s3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        c1.close (); c2.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        s1.close (); s2.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        /* check if connect() timesout when connecting to unknown dest. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        c1 = new Socket();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        t1 = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        InetSocketAddress ad1 = new InetSocketAddress (ia6bad, 2500);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            c1.connect (ad1, 5000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            throw new RuntimeException ("timeout exception was expected");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        } catch (SocketTimeoutException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            t1 = System.currentTimeMillis() - t1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            checkTime (t1, 5000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        } catch (NoRouteToHostException e1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        System.out.println ("Test3: OK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    /* Test: connect to IPv4 mapped address  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    static void test4 () throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        server = new ServerSocket (0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        int port = server.getLocalPort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        /* create an IPv4 mapped address corresponding to local host */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        byte[] b = {0,0,0,0,0,0,0,0,0,0,(byte)0xff,(byte)0xff,0,0,0,0};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        byte[] ia4 = ia4addr.getAddress();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        b[12] = ia4[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        b[13] = ia4[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        b[14] = ia4[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        b[15] = ia4[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        InetAddress dest = InetAddress.getByAddress (b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        c1 = new Socket (dest, port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        s1 = server.accept ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        simpleDataExchange (c1,s1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        c1.close ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        s1.close ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        server.close ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        System.out.println ("Test4: OK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
}