diff options
author | eea1 <eea1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1999-08-24 23:13:14 +0000 |
---|---|---|
committer | eea1 <eea1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1999-08-24 23:13:14 +0000 |
commit | 285a1a88b480f4fdd6758defe3f5200360f60483 (patch) | |
tree | def8416f985df21e79074dc73c52961fd7b5f611 /java | |
parent | 3c57abc16c67cde028d7786489156689127e6b2a (diff) | |
download | ATCD-285a1a88b480f4fdd6758defe3f5200360f60483.tar.gz |
Updated source files for tests/Connection.
Diffstat (limited to 'java')
-rw-r--r-- | java/JACE/tests/Connection/AcceptorTest.java | 83 | ||||
-rw-r--r-- | java/JACE/tests/Connection/ClientHandler.java | 77 | ||||
-rw-r--r-- | java/JACE/tests/Connection/ConnectorTest.java | 78 | ||||
-rw-r--r-- | java/JACE/tests/Connection/HTTPHelperTest.java | 34 | ||||
-rw-r--r-- | java/JACE/tests/Connection/ServerHandler.java | 68 |
5 files changed, 340 insertions, 0 deletions
diff --git a/java/JACE/tests/Connection/AcceptorTest.java b/java/JACE/tests/Connection/AcceptorTest.java new file mode 100644 index 00000000000..0e313ba1f43 --- /dev/null +++ b/java/JACE/tests/Connection/AcceptorTest.java @@ -0,0 +1,83 @@ +// ============================================================================ +// +// = PACKAGE +// tests.Connection +// +// = FILENAME +// AcceptorTest.java +// +// = AUTHOR +// Prashant Jain +// +// ============================================================================ +package JACE.tests.Connection; + +import java.io.*; +import java.net.*; +import JACE.OS.*; +import JACE.Connection.*; + +public class AcceptorTest +{ + void print_usage_and_die () + { + System.out.println ("Usage: test_server [<port>]"); + System.exit (0); + } + + public void init (int port) + { + try + { + Acceptor acceptor = + new Acceptor + (Class.forName ("JACE.tests.Connection.ServerHandler")); + acceptor.open (port); + while (true) + { + acceptor.accept (); + } + } + catch (ClassNotFoundException e) + { + ACE.ERROR (e); + } + catch (SocketException e) + { + ACE.ERROR ("Socket Exception: " + e); + } + catch (InstantiationException e) + { + ACE.ERROR (e); + } + catch (IllegalAccessException e) + { + ACE.ERROR ("Dang!" + e); + } + catch (IOException e) + { + ACE.ERROR (e); + } + } + + public static void main (String [] args) + { + int port = ACE.DEFAULT_SERVER_PORT; + AcceptorTest acceptorTest = new AcceptorTest (); + + ACE.enableDebugging (); + + if (args.length == 1) + { + try + { + port = Integer.parseInt (args[0]); + } + catch (NumberFormatException e) + { + acceptorTest.print_usage_and_die (); + } + } + acceptorTest.init (port); + } +} diff --git a/java/JACE/tests/Connection/ClientHandler.java b/java/JACE/tests/Connection/ClientHandler.java new file mode 100644 index 00000000000..d5885a892e9 --- /dev/null +++ b/java/JACE/tests/Connection/ClientHandler.java @@ -0,0 +1,77 @@ +// ============================================================================ +// +// = PACKAGE +// tests.Connection +// +// = FILENAME +// ClientHandler.java +// +// = AUTHOR +// Prashant Jain +// +// ============================================================================ +package JACE.tests.Connection; + +import java.io.*; +import java.net.*; +import JACE.OS.*; +import JACE.Connection.*; + +public class ClientHandler extends SvcHandler +{ + public ClientHandler () + { + } + + public int open (Object obj) + { + new Thread (this).start (); + return 0; + } + + public void run () + { + BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + + String msg; + StringBuffer ack = new StringBuffer (); + int ack_len; + try + { + while (true) + { + System.out.print ("Enter input: "); + System.out.flush (); + msg = in.readLine (); + if (msg == null) + break; + this.peer ().send (new StringBuffer (msg)); + System.out.println ("Waiting for ack..."); + ack_len = this.peer ().recv (ack); + if (ack_len == 0) + break; + else + System.out.println (ack); + } + } + catch (NullPointerException e) + { + ACE.ERROR ("connection reset by peer"); + } + catch (IOException e) + { + ACE.ERROR (e); + } + finally + { + try + { + this.peer ().close (); + } + catch (IOException e) + { + } + } + + } +} diff --git a/java/JACE/tests/Connection/ConnectorTest.java b/java/JACE/tests/Connection/ConnectorTest.java new file mode 100644 index 00000000000..285e492dcaf --- /dev/null +++ b/java/JACE/tests/Connection/ConnectorTest.java @@ -0,0 +1,78 @@ +// ============================================================================ +// +// = PACKAGE +// tests.Connection +// +// = FILENAME +// ConnectorTest.java +// +// = AUTHOR +// Prashant Jain +// +// ============================================================================ +package JACE.tests.Connection; + +import java.io.*; +import java.net.*; +import JACE.OS.*; +import JACE.Connection.*; + +public class ConnectorTest +{ + void print_usage_and_die () + { + System.out.println ("Usage: test_Connector <hostname> [<port>]"); + System.exit (0); + } + + public void init (String hostname, int port) + { + try + { + Connector connector = new Connector (); + connector.open (hostname, port); + connector.connect (new ClientHandler ()); + } + catch (UnknownHostException e) + { + ACE.ERROR (e); + } + catch (SocketException e) + { + ACE.ERROR ("Connection refused"); + } + catch (InstantiationException e) + { + ACE.ERROR (e); + } + catch (IllegalAccessException e) + { + ACE.ERROR (e); + } + catch (IOException e) + { + ACE.ERROR (e); + } + } + + public static void main (String [] args) + { + int port = ACE.DEFAULT_SERVER_PORT; + ConnectorTest connectorTest = new ConnectorTest (); + + ACE.enableDebugging (); + + if (args.length == 2) + { + try + { + port = Integer.parseInt (args[1]); + } + catch (NumberFormatException e) + { + connectorTest.print_usage_and_die (); + } + } + connectorTest.init (args[0], port); + } +} diff --git a/java/JACE/tests/Connection/HTTPHelperTest.java b/java/JACE/tests/Connection/HTTPHelperTest.java new file mode 100644 index 00000000000..28967acb8d3 --- /dev/null +++ b/java/JACE/tests/Connection/HTTPHelperTest.java @@ -0,0 +1,34 @@ +package JACE.tests.Connection; + +import java.io.*; +import JACE.Connection.*; +import JACE.OS.*; + +public class HTTPHelperTest +{ + public static void main(String args[]) + { + ACE.enableDebugging (); + // This is just a quick test to confirm that the Base 64 + // encoding and decoding work + // (tests the example given in the HTTP 1.1 RFC) + + String secret = "Aladdin:open sesame"; + + String encoded = HTTPHelper.EncodeBase64(secret); + + System.err.println("Encoding string: \"" + secret + '\"'); + + System.err.println("Result: \"" + encoded + '\"'); + + System.err.println("Is this right? " + + (encoded.equals("QWxhZGRpbjpvcGVuIHNlc2FtZQ==") ? + "Yes" : "No")); + + String decoded = HTTPHelper.DecodeBase64 (encoded); + System.err.println("Decoded: \"" + decoded + '\"'); + + System.err.println("Is this right? " + + (decoded.equals (secret) ? "Yes" : "No")); + } +} diff --git a/java/JACE/tests/Connection/ServerHandler.java b/java/JACE/tests/Connection/ServerHandler.java new file mode 100644 index 00000000000..4dec8186427 --- /dev/null +++ b/java/JACE/tests/Connection/ServerHandler.java @@ -0,0 +1,68 @@ +// ============================================================================ +// +// = PACKAGE +// tests.Connection +// +// = FILENAME +// ServerHandler.java +// +// = AUTHOR +// Prashant Jain +// +// ============================================================================ +package JACE.tests.Connection; + +import java.io.*; +import java.net.*; +import JACE.OS.*; +import JACE.Connection.*; + +public class ServerHandler extends SvcHandler +{ + public ServerHandler () + { + } + + public int open (Object obj) + { + new Thread (this).start (); + return 0; + } + + public void run () + { + int msg_len; + System.out.println ("Waiting for messages..."); + try + { + while (true) + { + StringBuffer msg = new StringBuffer (); + msg_len = this.peer ().recv (msg); + if (msg_len == 0) + break; + System.out.println ("Received: " + msg); + this.peer ().send (new StringBuffer ("Got it!")); + } + } + catch (NullPointerException e) + { + ACE.ERROR ("connection reset by peer"); + } + catch (IOException e) + { + ACE.ERROR (e); + } + finally + { + try + { + this.peer ().close (); + } + catch (IOException e) + { + } + } + + } +} |