1 /**************************************************/
\r
2 /* opengate client */
\r
3 /**************************************************
\r
5 java applet downloaded to client machine
\r
7 Copyright (C) 1999-2002 Opengate Project Team
\r
9 This program is free software; you can redistribute it and/or
\r
10 modify it under the terms of the GNU General Public License
\r
11 as published by the Free Software Foundation; either version 2
\r
12 of the License, or (at your option) any later version.
\r
14 This program is distributed in the hope that it will be useful,
\r
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
17 GNU General Public License for more details.
\r
19 You should have received a copy of the GNU General Public License
\r
20 along with this program; if not, write to the Free Software
\r
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
\r
24 Email: watanaby@is.saga-u.ac.jp
\r
26 Written by Yoshiaki WATANABE, Saga University
\r
27 Modified by Shin-ichi TADAKI, Saga University
\r
28 **************************************************/
\r
30 import java.applet.*;
\r
34 /** Wrapper to make Applet **/
\r
35 public class Opengate extends Applet{
\r
42 int intlang=0;/* if language is japanese, set 1*/
\r
43 OpengateClient client;
\r
48 /* Applet initialize */
\r
51 /* Get Applet Parameters */
\r
52 port=Integer.parseInt(getParameter("port"));
\r
53 userid=getParameter("user");
\r
54 sessionId=getParameter("sessionid");
\r
55 hostname =getCodeBase().getHost();
\r
56 language = getParameter("lang");
\r
57 if(language.equals("ja")) intlang=1;
\r
58 if(language.equals("en")) intlang=2;
\r
61 setLayout(new FlowLayout(FlowLayout.CENTER));
\r
62 setBackground(Color.yellow);
\r
66 add(headlabel=new Label("
\83l
\83b
\83g
\83\8f\81[
\83N
\97\98\97p
\8b\96\89Â"));
\r
67 add(userlabel=new Label("
\83\86\81[
\83U
\96¼="+userid));
\r
68 add(msglabel=new Label("Java Applet
\82ª
\8bN
\93®
\82µ
\82Ü
\82µ
\82½
\81@
\81@
\81@
\81@
\81@
\81@
\81@
\81@ "));
\r
70 add(headlabel=new Label("Authenticated for network use"));
\r
71 add(userlabel=new Label("User name="+userid));
\r
72 add(msglabel=new Label("Java Applet is running "));
\r
75 /* Connect to Server */
\r
76 client=new OpengateClient(hostname, port, userid, sessionId, intlang, this);
\r
79 public void msgout(String msg){
\r
80 /* byte[] code = msg.getBytes("EUCJIS");
\r
81 String msgj=new String(code,"EUCJIS");
\r
83 /* padding space char to required length */
\r
84 for(int i=msg.length();i<40;i++) msg+=" ";
\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
104 PrintStream outStream; /* output stream to server */
\r
105 BufferedReader inStream; /* input stream from server */
\r
106 String currentReply; /* reserve last reply from server */
\r
107 boolean onLine; /* Client is connected to server or not */
\r
108 Opengate main; /* main class */
\r
111 /* Instance Creater */
\r
112 public OpengateClient(String hostname, int port,
\r
113 String userid, String sessionId, int intlang, Opengate main){
\r
114 this.hostname=hostname;
\r
116 this.userid=userid;
\r
117 this.sessionId=sessionId;
\r
119 this.intlang=intlang;
\r
123 /* connect to server */
\r
127 main.msgout("
\83z
\83X
\83g"+hostname+":"+Integer.toString(port)+"
\82É
\90Ú
\91±
\92\86\82Å
\82·");
\r
129 main.msgout("Connecting to host "+hostname+":"+Integer.toString(port));
\r
131 socket=new Socket(hostname, port);
\r
132 outStream=new PrintStream(socket.getOutputStream());
\r
133 inStream=new BufferedReader(
\r
134 new InputStreamReader(
\r
135 socket.getInputStream()));
\r
136 }catch(UnknownHostException e){
\r
138 main.msgout("SocketConnect
\92\86\82ÉUnknownHost
\97á
\8aO
\82ª
\94
\90¶
\82µ
\82Ü
\82µ
\82½");
\r
140 main.msgout("UnknownHost exception in SocketConnect");
\r
142 }catch(IOException e){
\r
144 main.msgout("SocketConnect
\92\86\82ÉI/O
\97á
\8aO
\82ª
\94
\90¶
\82µ
\82Ü
\82µ
\82½");
\r
146 main.msgout("I/O exception in SocketConnect");
\r
153 /* disconnect from server */
\r
161 }catch(IOException e){
\r
163 main.msgout("SocketClose
\92\86\82ÉI/O
\97á
\8aO
\82ª
\94
\90¶
\82µ
\82Ü
\82µ
\82½");
\r
165 main.msgout("I/O exception in SocketClose");
\r
170 /* put out one line to server */
\r
171 void putLine(String string){
\r
172 outStream.print(string+"\r\n");
\r
175 /* get one line from server */
\r
178 currentReply=inStream.readLine();
\r
179 }catch(IOException e){
\r
181 main.msgout("SocketRead
\92\86\82ÉI/O
\97á
\8aO
\82ª
\94
\90¶
\82µ
\82Ü
\82µ
\82½");
\r
183 main.msgout("I/O exception in SocketRead");
\r
186 return currentReply;
\r
189 /* called back from client.start */
\r
192 java.text.SimpleDateFormat formatter
\r
193 =new java.text.SimpleDateFormat("H:mm") ;
\r
194 if(connect()==false){
\r
198 putLine(userid+"-"+sessionId);
\r
199 if(getLine().indexOf("accept")==-1){
\r
201 main.msgout("
\83T
\81[
\83o
\82©
\82çAccept
\82ª
\91\97\82ç
\82ê
\82Ä
\97\88\82Ü
\82¹
\82ñ");
\r
203 main.msgout("Not receive Accept from the server");
\r
208 main.msgout("
\90³
\8fí
\82É
\8aJ
\8en
\82µ
\82Ü
\82µ
\82½");
\r
210 main.msgout("Start Normally");
\r
212 while(getLine().indexOf("hello")!=-1){
\r
215 main.msgout("
\90Ú
\91±
\8am
\94F="+formatter.format(new java.util.Date()));
\r
217 main.msgout("Confirm connection="+formatter.format(new java.util.Date()));
\r
221 main.msgout("
\83l
\83b
\83g
\83\8f\81[
\83N
\82Í
\95Â
\8d½
\82³
\82ê
\82Ü
\82µ
\82½");
\r
223 main.msgout("Connection closed");
\r