test/jdk/sun/security/ssl/AppOutputStream/NoExceptionOnClose.java
author jjiang
Mon, 21 May 2018 15:40:25 +0800
branchJDK-8145252-TLS13-branch
changeset 56579 fb93f16d20fa
parent 47216 71c04702a3d5
child 56750 2b4ae319412b
permissions -rw-r--r--
sun/security/ssl/AppOutputStream/NoExceptionOnClose.java changes the expected exception
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
56579
fb93f16d20fa sun/security/ssl/AppOutputStream/NoExceptionOnClose.java changes the expected exception
jjiang
parents: 47216
diff changeset
     2
 * Copyright (c) 2001, 2018, 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 1.3 01/03/08
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 4378397
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary  JSSE socket output stream doesn't throw after socket is closed
10328
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    28
 * @run main/othervm NoExceptionOnClose
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    29
 *
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    30
 *     SunJSSE does not support dynamic system properties, no way to re-use
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    31
 *     system properties in samevm/agentvm mode.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * @author Jaya Hangal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.net.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.net.ssl.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
public class NoExceptionOnClose {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
     * =============================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
     * Set the various variables needed for the tests, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
     * specify what tests to run on each side.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * Should we run the client or server in a separate thread?
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * Both sides can throw exceptions, but do you have a preference
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * as to which side should be the main thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    static boolean separateServerThread = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * Where do we find the keystores?
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     */
23052
241885315119 8032473: Restructure JSSE regression test hierarchy in jdk test
xuelei
parents: 14342
diff changeset
    57
    static String pathToStores = "../../../../javax/net/ssl/etc";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    static String keyStoreFile = "keystore";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    static String trustStoreFile = "truststore";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    static String passwd = "passphrase";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * Is the server ready to serve?
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    volatile static boolean serverReady = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * Turn on SSL debugging?
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    static boolean debug = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    boolean useSSL = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * If the client or server is doing some kind of object creation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * that the other side depends on, and that thread prematurely
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * exits, you may experience a hang.  The test harness will
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * terminate all hung threads after its timeout has expired,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * currently 3 minutes by default, but you might try to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * smart about it....
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * Define the server side of the test.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * If the server prematurely exits, serverReady will be set to true
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * to avoid infinite hangs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    void doServerSide() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        ServerSocket  serverSocket;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        if (useSSL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            SSLServerSocketFactory sslssf =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            serverSocket = (SSLServerSocket) sslssf.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                        createServerSocket(serverPort);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
           serverSocket = new ServerSocket(serverPort);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        serverPort = serverSocket.getLocalPort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
         * Signal Client, we're ready for his connect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        serverReady = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        Socket socket =  serverSocket.accept();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        InputStream sslIS = socket.getInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        OutputStream sslOS = socket.getOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        int read = sslIS.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        System.out.println("Server read: " + read);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        sslOS.write(85);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        sslOS.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        socket.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        socket.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * Define the client side of the test.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * If the server prematurely exits, serverReady will be set to true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * to avoid infinite hangs.
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 server to get started.
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
        Socket socket;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        if (useSSL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            SSLSocketFactory sslsf =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                        (SSLSocketFactory) SSLSocketFactory.getDefault();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            socket = (SSLSocket)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                sslsf.createSocket("localhost", serverPort);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                socket = new Socket("localhost", serverPort);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        InputStream sslIS = socket.getInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        OutputStream sslOS = socket.getOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        sslOS.write(80);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        sslOS.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        int read = sslIS.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        System.out.println("client read: " + read);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        socket.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
         * The socket closed exception must be thrown here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        boolean isSocketClosedThrown = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            sslOS.write(22);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            sslOS.flush();
56579
fb93f16d20fa sun/security/ssl/AppOutputStream/NoExceptionOnClose.java changes the expected exception
jjiang
parents: 47216
diff changeset
   155
        } catch (SSLException socketClosed) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                System.out.println("Received \"" + socketClosed.getMessage()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                        + "\" exception as expected");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                isSocketClosedThrown = true;
56579
fb93f16d20fa sun/security/ssl/AppOutputStream/NoExceptionOnClose.java changes the expected exception
jjiang
parents: 47216
diff changeset
   159
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        if (!isSocketClosedThrown) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                throw new Exception("No Exception thrown on write() after"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                                + " close()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * =============================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * The remainder is just support stuff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    // use any free port by default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    volatile int serverPort = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    volatile Exception serverException = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    volatile Exception clientException = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        String keyFilename =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            System.getProperty("test.src", "./") + "/" + pathToStores +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                "/" + keyStoreFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        String trustFilename =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            System.getProperty("test.src", "./") + "/" + pathToStores +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                "/" + trustStoreFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        System.setProperty("javax.net.ssl.keyStore", keyFilename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        System.setProperty("javax.net.ssl.keyStorePassword", passwd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        System.setProperty("javax.net.ssl.trustStore", trustFilename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        System.setProperty("javax.net.ssl.trustStorePassword", passwd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        if (debug)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            System.setProperty("javax.net.debug", "all");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
         * Start the tests.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        new NoExceptionOnClose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    Thread clientThread = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    Thread serverThread = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * Primary constructor, used to drive remainder of the test.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * Fork off the other side, then do your work.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    NoExceptionOnClose() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        if (separateServerThread) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            startServer(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            startClient(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            startClient(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            startServer(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
         * Wait for other side to close down.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        if (separateServerThread) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            serverThread.join();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            clientThread.join();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
         * When we get here, the test is pretty much over.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
         * If the main thread excepted, that propagates back
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
         * immediately.  If the other thread threw an exception, we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
         * should report back.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        if (serverException != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            throw serverException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        if (clientException != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            throw clientException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    void startServer(boolean newThread) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        if (newThread) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            serverThread = new Thread() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                        doServerSide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                    } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                         * Our server thread just died.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                         * Release the client, if not active already...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                        System.err.println("Server died...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                        serverReady = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                        serverException = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            serverThread.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            doServerSide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    void startClient(boolean newThread) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        if (newThread) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            clientThread = new Thread() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                        doClientSide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                    } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                         * Our client thread just died.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                        System.err.println("Client died...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                        clientException = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            clientThread.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            doClientSide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
}