jdk/test/sun/security/ssl/com/sun/net/ssl/internal/ssl/SSLSocketImpl/ClientModeClientAuth.java
author ohair
Tue, 28 Dec 2010 15:53:50 -0800
changeset 7668 d4a77089c587
parent 7043 5e2d1edeb2c7
child 10328 06c93c42bca0
permissions -rw-r--r--
6962318: Update copyright year Reviewed-by: xdono
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 7043
diff changeset
     2
 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
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 4390659
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
    27
 * @run main/othervm -Djavax.net.debug=all ClientModeClientAuth
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @summary setNeedClientAuth() isn't working after a handshaker is established
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * @author Brad Wetmore
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.net.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.net.ssl.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.security.cert.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
public class ClientModeClientAuth {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
     * =============================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
     * Set the various variables needed for the tests, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
     * specify what tests to run on each side.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * Should we run the client or server in a separate thread?
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * Both sides can throw exceptions, but do you have a preference
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * as to which side should be the main thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    static boolean separateServerThread = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * Where do we find the keystores?
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    static String pathToStores = "../../../../../../../etc";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    static String keyStoreFile = "keystore";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    static String trustStoreFile = "truststore";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    static String passwd = "passphrase";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * Is the server ready to serve?
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    volatile static boolean serverReady = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * Define the server side of the test.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    void doServerSide() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        ServerSocket serverSocket = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        serverSocket = new ServerSocket(serverPort);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        serverPort = serverSocket.getLocalPort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
         * Signal Client, we're ready for his connect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        serverReady = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        Socket socket = serverSocket.accept();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        OutputStream out = socket.getOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        InputStream in = socket.getInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
         * send data to make sure we are ok.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        out.write(85);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        out.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        SSLSocketFactory sslsf =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            (SSLSocketFactory) SSLSocketFactory.getDefault();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        SSLSocket sslSocket =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            (SSLSocket) sslsf.createSocket(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                socket, socket.getInetAddress().getHostName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                socket.getPort(), true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        sslSocket.setUseClientMode(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        sslSocket.setNeedClientAuth(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        InputStream sslIS = sslSocket.getInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        OutputStream sslOS = sslSocket.getOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        sslOS.write(85);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        sslOS.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        sslIS.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        System.out.println("About to get PeerCertificates");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        Certificate[] certs =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            sslSocket.getSession().getPeerCertificates();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        if (certs[0] instanceof X509Certificate) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            System.out.println("Peer: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                ((X509Certificate)certs[0]).getSubjectDN());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        sslIS.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        sslOS.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        sslSocket.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * Define the client side of the test.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    void doClientSide() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
         * Wait for host to set up his port.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        while (!serverReady) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            Thread.sleep(50);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        Socket socket = new Socket("localhost", serverPort);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        InputStream in = socket.getInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        OutputStream out = socket.getOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        out.write(280);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        out.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        SSLSocketFactory sslsf =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            (SSLSocketFactory) SSLSocketFactory.getDefault();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        SSLSocket sslSocket = (SSLSocket)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            sslsf.createSocket(socket, socket.getInetAddress().getHostName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                socket.getPort(), true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        sslSocket.setUseClientMode(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        InputStream sslIS = sslSocket.getInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        OutputStream sslOS = sslSocket.getOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        sslIS.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        sslOS.write(280);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        sslOS.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        sslIS.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        sslOS.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        sslSocket.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * =============================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * The remainder is just support stuff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    // use any free port by default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    volatile int serverPort = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    volatile Exception serverException = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    volatile Exception clientException = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        String keyFilename =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            System.getProperty("test.src", "./") + "/" + pathToStores +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                "/" + keyStoreFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        String trustFilename =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            System.getProperty("test.src", "./") + "/" + pathToStores +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                "/" + trustStoreFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        System.setProperty("javax.net.ssl.keyStore", keyFilename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        System.setProperty("javax.net.ssl.keyStorePassword", passwd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        System.setProperty("javax.net.ssl.trustStore", trustFilename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        System.setProperty("javax.net.ssl.trustStorePassword", passwd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
         * Start the tests.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        new ClientModeClientAuth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    Thread clientThread = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    Thread serverThread = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    ClientModeClientAuth() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        if (separateServerThread) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            startServer(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            startClient(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            startClient(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            startServer(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
         * Wait for other side to close down.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        if (separateServerThread) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            serverThread.join();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            clientThread.join();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
         * When we get here, the test is pretty much over.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
         * If the main thread excepted, that propagates back
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
         * immediately.  If the other thread threw an exception, we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
         * should report back.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        if (serverException != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            throw serverException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        if (clientException != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            throw clientException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    void startServer(boolean newThread) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        if (newThread) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            serverThread = new Thread() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                        doServerSide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                    } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                         * Our server thread just died.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                         * Release the client, if not active already...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                        System.out.println("Server died...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                        serverReady = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                        serverException = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            serverThread.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            doServerSide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    void startClient(boolean newThread) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        if (newThread) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            clientThread = new Thread() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                        doClientSide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                    } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                         * Our client thread just died.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                        System.out.println("Client died...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                        clientException = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            clientThread.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            doClientSide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
}