diff options
author | eea1 <eea1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1999-08-24 23:13:38 +0000 |
---|---|---|
committer | eea1 <eea1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1999-08-24 23:13:38 +0000 |
commit | 377632e7f3dbc0b73c7eb4f42cf06a25cb6068ea (patch) | |
tree | a88fd3b8b123a574a4f3a02c57e4e5269afb5140 /java | |
parent | 8b948632e15be50020e0087ce6f846120fb662b8 (diff) | |
download | ATCD-377632e7f3dbc0b73c7eb4f42cf06a25cb6068ea.tar.gz |
Updated source files for tests/SOCK_SAP.
Diffstat (limited to 'java')
-rw-r--r-- | java/JACE/tests/SOCK_SAP/SOCKAcceptorTest.java | 110 | ||||
-rw-r--r-- | java/JACE/tests/SOCK_SAP/SOCKConnectorTest.java | 97 |
2 files changed, 207 insertions, 0 deletions
diff --git a/java/JACE/tests/SOCK_SAP/SOCKAcceptorTest.java b/java/JACE/tests/SOCK_SAP/SOCKAcceptorTest.java new file mode 100644 index 00000000000..3251030fe1c --- /dev/null +++ b/java/JACE/tests/SOCK_SAP/SOCKAcceptorTest.java @@ -0,0 +1,110 @@ +// ============================================================================ +// +// = PACKAGE +// tests.SOCK_SAP +// +// = FILENAME +// SOCKAcceptorTest.java +// +// = AUTHOR +// Prashant Jain +// +// ============================================================================ +package JACE.tests.SOCK_SAP; + +import java.io.*; +import java.net.*; +import JACE.OS.*; +import JACE.SOCK_SAP.*; + +class TestHandler extends Thread +{ + public TestHandler (SOCKStream stream) + { + this.stream_ = stream; + } + + public void run () + { + int msgLen; + System.out.println ("Waiting for messages..."); + try + { + while (true) + { + StringBuffer msg = new StringBuffer (); + msgLen = this.stream_.recv (msg); + if (msgLen == 0) + break; + ACE.DEBUG ("Received: " + msg); + this.stream_.send ("Got it!"); + } + } + catch (NullPointerException e) + { + ACE.ERROR ("connection reset by peer"); + } + catch (IOException e) + { + ACE.ERROR (e); + } + finally + { + try + { + this.stream_.close (); + } + catch (IOException e) + { + } + } + } + SOCKStream stream_; +} + +public class SOCKAcceptorTest +{ + void print_usage_and_die () + { + ACE.DEBUG ("Usage: SOCKAcceptorTest [<port>]"); + System.exit (0); + } + + public void init (int port) + { + try + { + SOCKAcceptor acceptor = new SOCKAcceptor (port); + while (true) + { + SOCKStream stream = new SOCKStream (); + acceptor.accept (stream); + TestHandler handler = new TestHandler (stream); + handler.start (); + } + } + catch (IOException e) + { + } + } + + public static void main (String [] args) + { + ACE.enableDebugging (); + + int port = ACE.DEFAULT_SERVER_PORT; + SOCKAcceptorTest server = new SOCKAcceptorTest (); + if (args.length == 1) + { + try + { + port = Integer.parseInt (args[0]); + } + catch (NumberFormatException e) + { + server.print_usage_and_die (); + } + } + server.init (port); + } +} diff --git a/java/JACE/tests/SOCK_SAP/SOCKConnectorTest.java b/java/JACE/tests/SOCK_SAP/SOCKConnectorTest.java new file mode 100644 index 00000000000..e14b63936f5 --- /dev/null +++ b/java/JACE/tests/SOCK_SAP/SOCKConnectorTest.java @@ -0,0 +1,97 @@ +// ============================================================================ +// +// = PACKAGE +// tests.SOCK_SAP +// +// = FILENAME +// SOCKConnectorTest.java +// +// = AUTHOR +// Prashant Jain +// +// ============================================================================ +package JACE.tests.SOCK_SAP; + +import java.io.*; +import java.net.*; +import JACE.OS.*; +import JACE.SOCK_SAP.*; + +public class SOCKConnectorTest +{ + static void print_usage_and_die () + { + System.out.println ("Usage: SOCKConnectorTest <hostname> [<port>]"); + System.exit (0); + } + + void processRequests (SOCKStream stream) throws IOException + { + // 1.0 JDK DataInputStream in = new DataInputStream (System.in); + BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + String msg; + int ack_len; + + while (true) + { + StringBuffer ack = new StringBuffer (); + ACE.DEBUG ("Enter input: "); + ACE.FLUSH (); + msg = in.readLine (); + if (msg == null) + break; + stream.send (msg); + ACE.DEBUG ("Waiting for ack..."); + ack_len = stream.recv (ack); + if (ack_len == 0) + break; + else + ACE.DEBUG (ack.toString ()); + } + } + + public void init (String host, int port) + { + SOCKStream stream = new SOCKStream (); + SOCKConnector connector = new SOCKConnector (); + try + { + connector.connect (stream, + host, + port); + processRequests (stream); + } + catch (IOException e) + { + ACE.ERROR (e); + } + } + + public static void main (String [] args) + { + ACE.enableDebugging (); + + int port = ACE.DEFAULT_SERVER_PORT; + SOCKConnectorTest client = new SOCKConnectorTest (); + + // check arg count + if (args.length == 0 || args.length > 2) + print_usage_and_die(); + + if (args.length == 2) + { + try + { + port = Integer.parseInt (args[1]); + } + catch (NumberFormatException e) + { + client.print_usage_and_die (); + } + } + client.init (args[0], port); + + + } +} + |