Annotation of OpenXM/src/OpenMath/oxclient.java, Revision 1.1
1.1 ! tam 1: /**
! 2: * $OpenXM$
! 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:
! 72: switch(message.getTag()){
! 73: case OXmessage.OX_COMMAND:
! 74: con.appendText("SM> "+ message.getBody() +"\n");
! 75: break;
! 76:
! 77: case OXmessage.OX_DATA:
! 78: con.appendText("CMO> "+ message.getBody() +"\n");
! 79: break;
! 80: }
! 81: }
! 82: }catch(IOException e){
! 83: e.printStackTrace();
! 84: }finally{
! 85: System.err.println("breaking...");
! 86: }
! 87: }
! 88:
! 89: public static String usage(){
! 90: return "\n";
! 91: }
! 92:
! 93: public static void main(String[] argv) throws IOException{
! 94: OpenXM asir;
! 95: String host = "localhost";
! 96: int CtrlPort = 1200,StreamPort = 1300;
! 97:
! 98: for(int i=0;i<argv.length;i++){
! 99: if(argv[i].equals("-h")){
! 100: System.err.print(usage());
! 101: System.exit(0);
! 102: }else if(argv[i].equals("-host")){
! 103: host = argv[++i];
! 104: }else if(argv[i].equals("-data")){
! 105: StreamPort = Integer.valueOf(argv[++i]).intValue();
! 106: }else if(argv[i].equals("-control")){
! 107: CtrlPort = Integer.valueOf(argv[++i]).intValue();
! 108: }else{
! 109: System.err.println("unknown option :"+ argv[i]);
! 110: System.exit(1);
! 111: }
! 112: }
! 113:
! 114: new oxclient(host,CtrlPort,StreamPort);
! 115: }
! 116: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>