Annotation of OpenXM/src/OpenMath/testclient.java, Revision 1.4
1.1 tam 1: /**
1.4 ! ohara 2: * $OpenXM: OpenXM/src/OpenMath/testclient.java,v 1.3 2000/10/11 08:32:14 ohara Exp $
1.1 tam 3: *
4: */
5:
6: import java.io.*;
1.4 ! ohara 7: import ORG.openxm.tam.*;
1.1 tam 8:
9: final class testclient{
10: private OpenXM asir; // for debug
11:
12: public static String usage(){
13: return "\n";
14: }
15:
16: public static void main(String[] argv) throws IOException{
17: OpenXM asir;
18: String host = "localhost";
19: int CtrlPort = 1200,StreamPort = 1300;
20:
21: for(int i=0;i<argv.length;i++){
22: if(argv[i].equals("-h")){
1.3 ohara 23: System.err.print(usage());
1.1 tam 24: System.exit(0);
25: }else if(argv[i].equals("-host")){
26: host = argv[++i];
27: }else if(argv[i].equals("-data")){
28: StreamPort = Integer.valueOf(argv[++i]).intValue();
29: }else if(argv[i].equals("-control")){
30: CtrlPort = Integer.valueOf(argv[++i]).intValue();
31: }else{
32: System.err.println("unknown option :"+ argv[i]);
33: System.exit(1);
34: }
35: }
36:
37: try{ // connect to server
38: asir = new OpenXM(host,CtrlPort,StreamPort);
39: }catch(java.net.UnknownHostException e){
40: System.err.println("host unknown.");
41: System.err.println(e.getMessage());
42: return;
43: }catch(IOException e){
44: System.err.println("connection failed.");
45: System.err.println("IOException occuer !!");
46: System.err.println(e.getMessage());
47: return;
48: }
49:
1.3 ohara 50: System.err.println("start");
1.1 tam 51:
52: try{ // send data to server
53: asir.send(new SM(SM.SM_mathcap));
54: asir.send(new SM(SM.SM_popCMO));
55: asir.send(new CMO_ZZ("12345678901234567890"));
56: asir.send(new SM(SM.SM_popCMO));
57: }catch(NumberFormatException e){
58: System.err.println(e.getMessage());
59: }catch(MathcapViolation e){
60: System.err.println(e.getMessage());
61: }
62:
63: try{ // receive a data which come from server
64: while(true){
1.2 tam 65: OXmessage message = asir.receive();
1.1 tam 66:
1.2 tam 67: switch(message.getTag()){
68: case OXmessage.OX_COMMAND:
1.3 ohara 69: System.err.println("SM> "+ message.getBody());
1.1 tam 70: break;
71:
1.2 tam 72: case OXmessage.OX_DATA:
1.3 ohara 73: System.err.println("CMO> "+ message.getBody());
1.1 tam 74: break;
75: }
76: }
77: }catch(IOException e){
78: e.printStackTrace();
79: }finally{
1.3 ohara 80: System.err.println("breaking...");
1.1 tam 81: }
82: }
83: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>