version 1.3, 2000/09/08 07:29:45 |
version 1.11, 2021/03/29 02:35:12 |
|
|
/** |
/** |
* $OpenXM: OpenXM/src/OpenMath/ORG/openxm/tam/OpenXM.java,v 1.2 2000/09/07 11:07:01 tam Exp $ |
* $OpenXM: OpenXM/src/OpenMath/ORG/openxm/tam/OpenXM.java,v 1.10 2002/10/27 10:39:32 takayama Exp $ |
*/ |
*/ |
package ORG.openxm.tam; |
package ORG.openxm.tam; |
|
|
|
|
import java.net.*; |
import java.net.*; |
|
|
|
|
|
/*&ja |
|
OpenXM サーバとの接続を行なうクラス. |
|
クライアント側が使用する. |
|
接続するサーバ毎に一つの OpenXM クラスが必要. |
|
*/ |
/** |
/** |
* OpenXM ФȤ³Ԥʤ饹. |
* OpenXM is a class to connect to OpenXM servers, |
* 饤¦Ѥ. |
* which are compliant to OpenXM RFC 100. |
* ³륵˰Ĥ OpenXM 饹ɬ. |
* There is one-to-one correspondence between the instances |
|
* of the class OpenXM and the OpenXM servers. |
*/ |
*/ |
public class OpenXM{ |
public class OpenXM{ |
private OpenXMconnection control = null, stream = null; |
private OpenXMstream control = null, stream = null; |
final protected boolean debug = false; |
final protected boolean debug = false; |
|
|
|
/*&ja |
|
* OpenXM サーバとの接続を TCP/IP ソケットを用いて行なう. |
|
* マシン名 host のポート番号 CtrlPort にコントロールを, |
|
* ポート番号 StreamPort にデータ用の接続を行なう. |
|
*/ |
/** |
/** |
* OpenXM ФȤ³ TCP/IP åȤѤƹԤʤ. |
* Connect to an OpenXM server via TCP/IP socket. |
* ޥ̾ host Υݡֹ CtrlPort ˥ȥ, |
* @param host a machine name of the OpenXM server. |
* ݡֹ StreamPort ˥ǡѤ³Ԥʤ. |
* @param CtrlPort the control port number of the OpenXM server. |
|
* @param StreamPort the data port number of the OpenXM server. |
|
* As to details on the notion of control port and data port, see |
|
* Design and Implementation of OpenXM client server model and |
|
* common mathematical object format (OpenXM-RFC 100, |
|
* proposed standard) |
|
* @see <a href="http://www.openxm.org">OpenXM</a> |
*/ |
*/ |
public OpenXM(String host,int CtrlPort,int StreamPort) throws IOException{ |
public OpenXM(String host,int CtrlPort,int StreamPort) throws IOException{ |
control = new OpenXMconnection(host,CtrlPort); |
control = new OpenXMstream(host,CtrlPort); |
|
|
try{ |
try{ |
Thread.sleep(100); // We need a few wait for starting up server. |
Thread.sleep(100); // We need a few wait for starting up server. |
Line 30 public class OpenXM{ |
|
Line 47 public class OpenXM{ |
|
System.err.println(e.getMessage()); |
System.err.println(e.getMessage()); |
} |
} |
|
|
stream = new OpenXMconnection(host,StreamPort); |
stream = new OpenXMstream(host,StreamPort); |
|
|
control.sendByteOrder(); |
control.sendByteOrder(); |
stream.sendByteOrder(); |
stream.sendByteOrder(); |
} |
} |
|
|
|
/*&ja |
|
* コマンド command を立ち上げ、 |
|
* OpenXM サーバとの接続を TCP/IP ソケットを用いて行なう. |
|
* マシン名 host のポート番号 CtrlPort にコントロールを, |
|
* ポート番号 StreamPort にデータ用の接続を行なう. |
|
*/ |
/** |
/** |
* ³νԤʤ. ߤ̤. |
* First, execute a command, which is usually an OpenXM server, |
|
* and next try to connect to the OpenXM server via TCP/IP. |
|
* @param command a command. |
|
* @param host a machine name of the OpenXM server. |
|
* @param CtrlPort the control port number of the OpenXM server. |
|
* @param StreamPort the data port number of the OpenXM server. |
*/ |
*/ |
|
public OpenXM(String command,String host,int CtrlPort,int StreamPort) |
|
throws IOException{ |
|
Runtime.getRuntime().exec(command); |
|
control = new OpenXMstream(host,CtrlPort); |
|
|
|
try{ |
|
Thread.sleep(100); // We need a few wait for starting up server. |
|
}catch(InterruptedException e){ |
|
System.err.println(e.getMessage()); |
|
} |
|
|
|
stream = new OpenXMstream(host,StreamPort); |
|
|
|
control.sendByteOrder(); |
|
stream.sendByteOrder(); |
|
} |
|
|
|
public OpenXM(String host,int CtrlPort,int StreamPort,String ox_server,int oxd_port,String pass) |
|
throws IOException{ |
|
// pass may be a null string. |
|
control = new OpenXMstream(host,CtrlPort,pass); |
|
stream = new OpenXMstream(host,StreamPort,pass); |
|
System.err.println("Listening..."); |
|
System.err.println("Launch ox server with the reverse option, e.g., ox -ox ox_asir -reverse"); |
|
// Launch ox_server by the oxd daemon (oxd_port). |
|
// BUG: It has not yet been implemented. |
|
control.OpenXMstreamAccept(); |
|
System.err.println("Accepted the control port."); |
|
stream.OpenXMstreamAccept(); |
|
System.err.println("Accepted the data port."); |
|
|
|
|
|
control.sendByteOrder(); |
|
stream.sendByteOrder(); |
|
} |
|
|
|
public OpenXM(String ox_server) throws IOException { |
|
int oxdPort = 8089; |
|
String host = "localhost"; |
|
oxdStream oxd = new oxdStream(oxdPort); |
|
int cport,dport; |
|
cport = oxd.startPhase1(); |
|
dport = cport+1; |
|
try { |
|
control = new OpenXMstream(host,cport,""); |
|
stream = new OpenXMstream(host,dport,""); |
|
}catch( IOException e) { |
|
System.err.println("Could not open ports for client."); |
|
oxd.write("<bye/>"); |
|
} |
|
|
|
System.err.println("Listenning..."); |
|
|
|
oxd.startPhase2(ox_server,cport); |
|
|
|
control.OpenXMstreamAccept(); |
|
System.err.println("Accepted the control port."); |
|
stream.OpenXMstreamAccept(); |
|
System.err.println("Accepted the data port."); |
|
|
|
|
|
control.sendByteOrder(); |
|
stream.sendByteOrder(); |
|
} |
|
|
|
|
|
/*&ja |
|
* サーバの計算中断を行なう. 現在は未実装. |
|
*/ |
|
/** |
|
* Resetting the engine process. It has not yet been implemented. |
|
*/ |
public synchronized void resetConnection(){ |
public synchronized void resetConnection(){ |
debug("control: stopping computer process..."); |
debug("control: stopping computer process..."); |
debug("control: sending SYNC BALL."); |
debug("control: sending SYNC BALL."); |
} |
} |
|
|
|
/*&ja |
|
* OpenXM メッセージをデータストリームに送信する. |
|
* このメソッドはメッセージのボディの部分だけでよい. |
|
* ヘッダ部分は自動で付加される. |
|
*/ |
/** |
/** |
* OpenXM åǡȥ. |
* Send an OpenXM message object. |
* ΥåɤϥåΥܥǥʬǤ褤. |
* @param object a message. For example, oxm.send(new CMO_STRING("Hello")) |
* إåʬϼưղä. |
* sends a string "Hello" to the OpenXM server oxm in the CMO_STRING data |
|
* encoding. |
*/ |
*/ |
public void send(OXbody object) throws IOException,MathcapViolation{ |
public void send(OXbody object) throws IOException,MathcapViolation{ |
stream.send(object); |
stream.send(object); |
} |
} |
|
|
|
/*&ja |
|
* データストリームから OpenXM メッセージを受け取る. |
|
*/ |
/** |
/** |
* ǡȥफ OpenXM å. |
* Receive an OpenXM message. |
*/ |
*/ |
public OXmessage receive() throws IOException{ |
public OXmessage receive() throws IOException{ |
return stream.receive(); |
return stream.receive(); |
} |
} |
|
|
|
/*&ja |
|
* データストリームの MathCap を mathcap に設定する. |
|
* 以後, 送信するオブジェクトは mathcap に合っているかどうか |
|
* チェックが入る. 実際にチェックが入るかどうかは |
|
* OXbody クラスの派生クラスの実装による. |
|
* mathcap に反したオブジェクトを送ろうとした時には, |
|
* 以後 MathcapViolation が発生することが期待される. |
|
*/ |
/** |
/** |
* ǡȥ MathCap mathcap ꤹ. |
* Set the mathcap. |
* ʸ, 륪֥Ȥ mathcap ˹äƤ뤫ɤ |
* If one tries to send an object which is prohibited to send by the mathcap, |
* å. ºݤ˥å뤫ɤ |
* the mathcapViolation exception is thrown. |
* OXbody 饹饹μˤ. |
|
* mathcap ȿ֥ȤȤˤ, |
|
* ʸ MathcapViolation ȯ뤳ȤԤ. |
|
*/ |
*/ |
public void setMathCap(CMO_MATHCAP mathcap){ |
public void setMathCap(CMO_MATHCAP mathcap){ |
stream.setMathCap(mathcap); |
stream.setMathCap(mathcap); |
Line 87 public class OpenXM{ |
|
Line 201 public class OpenXM{ |
|
|
|
for(int i=0;i<argv.length;i++){ |
for(int i=0;i<argv.length;i++){ |
if(argv[i].equals("-h")){ |
if(argv[i].equals("-h")){ |
System.out.println(""); |
System.err.println(""); |
System.exit(0); |
System.exit(0); |
}else if(argv[i].equals("-host")){ |
}else if(argv[i].equals("-host")){ |
hostname = argv[++i]; |
hostname = argv[++i]; |
Line 118 public class OpenXM{ |
|
Line 232 public class OpenXM{ |
|
} |
} |
|
|
try{ |
try{ |
//¦ʸޤ |
//サーバ側へ文字列を送信します。 |
ox.send(new SM(SM.SM_mathcap)); |
ox.send(new SM(SM.SM_mathcap)); |
ox.send(new SM(SM.SM_popString)); |
ox.send(new SM(SM.SM_popString)); |
|
|
Line 152 public class OpenXM{ |
|
Line 266 public class OpenXM{ |
|
|
|
//os.flush(); |
//os.flush(); |
|
|
//¦줿ʸޤ |
//サーバ側から送信された文字列を受信します。 |
while(true){ |
while(true){ |
ox.receive(); |
ox.receive(); |
} |
} |
Line 161 public class OpenXM{ |
|
Line 275 public class OpenXM{ |
|
e.printStackTrace(); |
e.printStackTrace(); |
} |
} |
|
|
System.out.println("breaking..."); |
System.err.println("breaking..."); |
|
|
try{ |
try{ |
// close connection |
// close connection |