Annotation of OpenXM/src/OpenMath/oxclient.java, Revision 1.2
1.1 tam 1: /**
1.2 ! tam 2: * $OpenXM: OpenXM/src/OpenMath/oxclient.java,v 1.1 2000/11/15 05:51:57 tam Exp $
1.1 tam 3: *
4: */
5:
6: import ORG.openxm.tam.*;
7: import java.io.*;
8: import java.awt.event.*;
9:
10: final class oxclient extends java.awt.Frame implements Runnable{
11: private OpenXM server;
12: private java.awt.TextArea con;
13: private java.awt.TextField command;
14:
15: public oxclient(String host,int CtrlPort,int StreamPort){
16: super("oxclient");
17: add("North",con = new java.awt.TextArea(24,80));
18: con.setEditable(false);
19: {
20: java.awt.Button button;
21: add("West",button = new java.awt.Button("execute"));
22: button.addActionListener(new ActionListener(){
23: public void actionPerformed(ActionEvent e) {
24: try{
25: server.send(new CMO_STRING(command.getText()));
26: server.send(new SM(SM.SM_executeStringByLocalParser));
27: server.send(new SM(SM.SM_popString));
28: }catch(Exception exc){}
29: command.setText("");
30: }
31: });
32: }
33: add("Center",command = new java.awt.TextField());
34: pack();
35: show();
36:
37: con.appendText("connecting...\n");
38: try{ // connect to server
39: server = new OpenXM(host,CtrlPort,StreamPort);
40: }catch(java.net.UnknownHostException e){
41: con.appendText("unknown host: "+ host +"\n");
42: return;
43: }catch(IOException e){
44: con.appendText("connection failed.\n");
45: System.err.println("IOException occuer !!");
46: System.err.println(e.getMessage());
47: return;
48: }
49: con.appendText("connected\n");
50:
51: try{ // send data to server
52: server.send(new SM(SM.SM_mathcap));
53: server.send(new SM(SM.SM_popCMO));
54: server.send(new CMO_ZZ("12345678901234567890"));
55: server.send(new SM(SM.SM_popCMO));
56: }catch(NumberFormatException e){
57: System.err.println(e.getMessage());
58: }catch(MathcapViolation e){
59: System.err.println(e.getMessage());
60: }catch(IOException e){
61: }
62: con.appendText("MATHCAP exchanged.\n");
63:
64: new Thread(this).start();
65: }
66:
67: public void run(){
68: try{ // receive a data which come from server
69: while(true){
70: OXmessage message = server.receive();
71:
1.2 ! tam 72: con.appendText("> "+ message.getBody() +"\n");
1.1 tam 73: }
74: }catch(IOException e){
75: e.printStackTrace();
76: }finally{
77: System.err.println("breaking...");
78: }
79: }
80:
81: public static String usage(){
82: return "\n";
83: }
84:
85: public static void main(String[] argv) throws IOException{
86: OpenXM asir;
87: String host = "localhost";
88: int CtrlPort = 1200,StreamPort = 1300;
89:
90: for(int i=0;i<argv.length;i++){
91: if(argv[i].equals("-h")){
92: System.err.print(usage());
93: System.exit(0);
94: }else if(argv[i].equals("-host")){
95: host = argv[++i];
96: }else if(argv[i].equals("-data")){
97: StreamPort = Integer.valueOf(argv[++i]).intValue();
98: }else if(argv[i].equals("-control")){
99: CtrlPort = Integer.valueOf(argv[++i]).intValue();
100: }else{
101: System.err.println("unknown option :"+ argv[i]);
102: System.exit(1);
103: }
104: }
105:
106: new oxclient(host,CtrlPort,StreamPort);
107: }
108: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>