Annotation of OpenXM/src/OpenMath/testclient.java, Revision 1.2
1.1 tam 1: /**
1.2 ! tam 2: * $OpenXM: OpenXM/src/OpenMath/testclient.java,v 1.1 2000/01/28 06:22:01 tam Exp $
1.1 tam 3: *
4: */
5:
6: import java.io.*;
7: import JP.ac.kobe_u.math.tam.OpenXM.*;
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")){
23: System.out.print(usage());
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:
50: System.out.println("start");
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:
! 69: System.out.println("SM> "+ message.getBody());
1.1 tam 70: break;
71:
1.2 ! tam 72: case OXmessage.OX_DATA:
! 73: System.out.println("CMO> "+ message.getBody());
1.1 tam 74: break;
75: }
76: }
77: }catch(IOException e){
78: e.printStackTrace();
79: }finally{
80: System.out.println("breaking...");
81: }
82: }
83: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>