1 /**************************************************/
\r
2 /* opengate client */
\r
4 /* Yoshiaki Watanabe, */
\r
5 /* Saga University, Japan, */
\r
6 /* E-Mail:watanaby@is.saga-u.ac.jp */
\r
7 /**************************************************
\r
9 java applet downloaded to client machine
\r
11 Copyright (C) 1999-2002 Yoshiaki Watanabe
\r
13 This program is free software; you can redistribute it and/or
\r
14 modify it under the terms of the GNU General Public License
\r
15 as published by the Free Software Foundation; either version 2
\r
16 of the License, or (at your option) any later version.
\r
18 This program is distributed in the hope that it will be useful,
\r
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
21 GNU General Public License for more details.
\r
23 You should have received a copy of the GNU General Public License
\r
24 along with this program; if not, write to the Free Software
\r
25 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
\r
28 Email: watanaby@is.saga-u.ac.jp
\r
30 Programmed by Yoshiaki WATANABE, Saga University
\r
31 Modified by Shin-ichi TADAKI, Saga University
\r
32 **************************************************/
\r
34 import java.applet.*;
\r
38 /** Wrapper to make Applet **/
\r
39 public class Opengate extends Applet{
\r
45 int intlang=0;/* if language is japanese, set 1*/
\r
46 OpengateClient client;
\r
51 /* Applet initialize */
\r
54 /* Get Applet Parameters */
\r
55 port=Integer.parseInt(getParameter("port"));
\r
56 userid=getParameter("user");
\r
57 hostname =getCodeBase().getHost();
\r
58 language = getParameter("lang");
\r
59 if(language.equals("ja")) intlang=1;
\r
60 if(language.equals("en")) intlang=2;
\r
63 setLayout(new FlowLayout(FlowLayout.CENTER));
\r
64 setBackground(Color.yellow);
\r
68 add(headlabel=new Label("
\83l
\83b
\83g
\83\8f\81[
\83N
\97\98\97p
\8b\96\89Â"));
\r
69 add(userlabel=new Label("
\83\86\81[
\83U
\96¼="+userid));
\r
70 add(msglabel=new Label("Java Applet
\82ª
\8bN
\93®
\82µ
\82Ü
\82µ
\82½
\81@
\81@
\81@
\81@
\81@
\81@
\81@
\81@ "));
\r
72 add(headlabel=new Label("Authenticated for network use"));
\r
73 add(userlabel=new Label("User name="+userid));
\r
74 add(msglabel=new Label("Java Applet is running
\81@
\81@
\81@
\81@
\81@
\81@
\81@
\81@ "));
\r
77 /* Connect to Server */
\r
78 client=new OpengateClient(hostname, port, userid, intlang, this);
\r
81 public void msgout(String msg){
\r
82 /* byte[] code = msg.getBytes("EUCJIS");
\r
83 String msgj=new String(code,"EUCJIS");
\r
85 msglabel.setText(msg);
\r
91 }catch(InterruptedException e){
\r
92 msgout("Error at Client Join ");
\r
97 /** Class for Client to communicate with host **/
\r
98 class OpengateClient extends Thread{
\r
99 int port; /* opengate port */
\r
100 String hostname; /* java download host name */
\r
101 Socket socket; /* Socket for server */
\r
103 PrintStream outStream; /* output stream to server */
\r
104 BufferedReader inStream; /* input stream from server */
\r
105 String currentReply; /* reserve last reply from server */
\r
106 boolean onLine; /* Client is connected to server or not */
\r
107 Opengate main; /* main class */
\r
110 /* Instance Creater */
\r
111 public OpengateClient(String hostname, int port,
\r
112 String userid, int intlang, Opengate main){
\r
113 this.hostname=hostname;
\r
115 this.userid=userid;
\r
117 this.intlang=intlang;
\r
121 /* connect to server */
\r
125 main.msgout("
\83z
\83X
\83g"+hostname+":"+Integer.toString(port)+"
\82É
\90Ú
\91±
\92\86\82Å
\82·");
\r
127 main.msgout("Connecting to host "+hostname+":"+Integer.toString(port));
\r
129 socket=new Socket(hostname, port);
\r
130 outStream=new PrintStream(socket.getOutputStream());
\r
131 inStream=new BufferedReader(
\r
132 new InputStreamReader(
\r
133 socket.getInputStream()));
\r
134 }catch(UnknownHostException e){
\r
136 main.msgout("SocketConnect
\92\86\82ÉUnknownHost
\97á
\8aO
\82ª
\94
\90¶
\82µ
\82Ü
\82µ
\82½");
\r
138 main.msgout("UnknownHost exception in SocketConnect");
\r
140 }catch(IOException e){
\r
142 main.msgout("SocketConnect
\92\86\82ÉI/O
\97á
\8aO
\82ª
\94
\90¶
\82µ
\82Ü
\82µ
\82½");
\r
144 main.msgout("I/O exception in SocketConnect");
\r
151 /* disconnect from server */
\r
159 }catch(IOException e){
\r
161 main.msgout("SocketClose
\92\86\82ÉI/O
\97á
\8aO
\82ª
\94
\90¶
\82µ
\82Ü
\82µ
\82½");
\r
163 main.msgout("I/O exception in SocketClose");
\r
168 /* put out one line to server */
\r
169 void putLine(String string){
\r
170 outStream.print(string+"\r\n");
\r
173 /* get one line from server */
\r
176 currentReply=inStream.readLine();
\r
177 }catch(IOException e){
\r
179 main.msgout("SocketRead
\92\86\82ÉI/O
\97á
\8aO
\82ª
\94
\90¶
\82µ
\82Ü
\82µ
\82½");
\r
181 main.msgout("I/O exception in SocketRead");
\r
184 return currentReply;
\r
187 /* called back from client.start */
\r
190 java.text.SimpleDateFormat formatter
\r
191 =new java.text.SimpleDateFormat("H:mm") ;
\r
192 if(connect()==false){
\r
197 if(getLine().indexOf("accept")==-1){
\r
199 main.msgout("
\83T
\81[
\83o
\82©
\82çAccept
\82ª
\91\97\82ç
\82ê
\82Ä
\97\88\82Ü
\82¹
\82ñ");
\r
201 main.msgout("Not receive Accept from the server");
\r
206 main.msgout("
\90³
\8fí
\82É
\8aJ
\8en
\82µ
\82Ü
\82µ
\82½");
\r
208 main.msgout("Start Normally");
\r
210 while(getLine().indexOf("hello")!=-1){
\r
213 main.msgout("
\90Ú
\91±
\8am
\94F="+formatter.format(new java.util.Date()));
\r
215 main.msgout("Confirm connection="+formatter.format(new java.util.Date()));
\r
219 main.msgout("
\83l
\83b
\83g
\83\8f\81[
\83N
\82Í
\95Â
\8d½
\82³
\82ê
\82Ü
\82µ
\82½");
\r
221 main.msgout("Connection closed");
\r