JavaアプリケーションとXPort間の連携は成功したので、Java AppletとXPort間の連携のテストをしました。手順は以下です。
- web2cob /o test.cob /d test
- tftp -i 10.10.10.50 PUT test.cob WEB3
- http://10.10.10.50/XPortTestApplet.html
以下は、シリアルポートに接続されたPCから入力されたキーコードがアプレット上に表示されるようにしたものです。
/* * XPortTestAplet.java : */ import java.io.*; import java.net.*; import java.applet.*; import java.awt.*; public class XPortTestApplet extends Applet implements Runnable{ private String XPORT_IP = "10.10.10.50"; private int XPORT_PORT = 10001; Socket soc; DataInputStream in; BufferedReader reader; int ch; Thread th; public void init(){ try { soc = new Socket(XPORT_IP,XPORT_PORT); in = new DataInputStream(soc.getInputStream()); } catch (IOException e){ e.printStackTrace(); } } public void start(){ th = new Thread(this); th.start(); } public void run(){ while(true){ try { ch = in.read(); repaint(); } catch (IOException e){ e.printStackTrace(); } } } public void paint(Graphics g){ g.drawString("" + ch,10,10); } }
HTMLファイルは以下です。
<html> <head> <title>XPortTestApplet</title> </head> <body> <applet code="XPortTestApplet.class" width="50" height="50"> </applet> </body> </html>