1 /*
2 * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
40 ServerSocket listener;
41 Socket client, server;
42 int clPort;
43 InputStream clis, sis;
44 OutputStream clos, sos;
45
46 static void usage () {
47 System.out.println (" usage: java UrgentDataTest <runs client and server together>");
48 System.out.println (" usage: java UrgentDataTest -server <runs server alone>");
49 System.out.println (" usage: java UrgentDataTest -client host port <runs client and connects to"+
50 " specified server>");
51 }
52
53 public static void main (String args[]) {
54 try {
55 UrgentDataTest test = new UrgentDataTest ();
56 if (args.length == 0) {
57 test.listener = new ServerSocket (0);
58 test.isClient = true;
59 test.isServer = true;
60 test.clHost = "127.0.0.1";
61 test.clPort = test.listener.getLocalPort();
62 test.run();
63 } else if (args[0].equals ("-server")) {
64 test.listener = new ServerSocket (0);
65 System.out.println ("Server listening on port " + test.listener.getLocalPort());
66 test.isClient = false;
67 test.isServer = true;
68 test.run();
69 System.out.println ("Server: Completed OK");
70 } else if (args[0].equals ("-client")) {
71 test.isClient = true;
72 test.isServer = false;
73 test.clHost = args [1];
74 test.clPort = Integer.parseInt (args[2]);
75 test.run();
76 System.out.println ("Client: Completed OK");
77 } else {
78 usage ();
79 }
80 }
|
1 /*
2 * Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
40 ServerSocket listener;
41 Socket client, server;
42 int clPort;
43 InputStream clis, sis;
44 OutputStream clos, sos;
45
46 static void usage () {
47 System.out.println (" usage: java UrgentDataTest <runs client and server together>");
48 System.out.println (" usage: java UrgentDataTest -server <runs server alone>");
49 System.out.println (" usage: java UrgentDataTest -client host port <runs client and connects to"+
50 " specified server>");
51 }
52
53 public static void main (String args[]) {
54 try {
55 UrgentDataTest test = new UrgentDataTest ();
56 if (args.length == 0) {
57 test.listener = new ServerSocket (0);
58 test.isClient = true;
59 test.isServer = true;
60 test.clHost = InetAddress.getLoopbackAddress().getHostAddress();
61 test.clPort = test.listener.getLocalPort();
62 test.run();
63 } else if (args[0].equals ("-server")) {
64 test.listener = new ServerSocket (0);
65 System.out.println ("Server listening on port " + test.listener.getLocalPort());
66 test.isClient = false;
67 test.isServer = true;
68 test.run();
69 System.out.println ("Server: Completed OK");
70 } else if (args[0].equals ("-client")) {
71 test.isClient = true;
72 test.isServer = false;
73 test.clHost = args [1];
74 test.clPort = Integer.parseInt (args[2]);
75 test.run();
76 System.out.println ("Client: Completed OK");
77 } else {
78 usage ();
79 }
80 }
|