summaryrefslogtreecommitdiff
path: root/java/netsvcs/Time/ClientTest.java
blob: e5453d692439c49c15fbd90217dcb78762d7c011 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package netsvcs.Time;

import JACE.SOCK_SAP.*;
import java.io.*; 
import java.net.*;
import JACE.OS.*;

public class ClientTest {

  public static void main(String args[])
    {
      // Don't worry about processing command line right now

      int port = 7990;
      
      String host = new String("flamenco.cs.wustl.edu");  
      // Why isn't the default defined?


      SOCKStream cli_stream = new SOCKStream();

      INETAddr remote_addr;
      try {
	remote_addr = new INETAddr(port, host);
      } catch (UnknownHostException uhe) {
	ACE.ERROR("UnknownHostException " + uhe);
	return;
      }

      SOCKConnector con = new SOCKConnector();

      ACE.DEBUG("Starting connect...");

      // Can't do non-blocking connect in Java!  Yippee!
 
      try {

	con.connect(cli_stream, remote_addr);

      } catch (SocketException se) {
	
	ACE.ERROR("Socket Exception " + se);
	return;

      } catch (IOException ie) {

	ACE.ERROR("IOException " + ie);
	return;
      }
    
      String input;  // need new string here?
      BufferedReader in
	= new BufferedReader(new InputStreamReader(System.in));
 
      try {

	do {

	  input = in.readLine();
	  
	  if (input.equals("quit"))
	    break;

	  cli_stream.send(new StringBuffer(input + "\n"));

	  StringBuffer result = new StringBuffer();
	  int chars = cli_stream.recv(result);
	  if (chars == -1)
	    System.out.println("Evil!");
	  else
	    System.out.println(result);

	} while (true);

	// No close_writer, etc...
	cli_stream.close();

      } catch (IOException ie) {

	ACE.ERROR("IOException, loop: " + ie);
	return;
      }
    }
};