Mercurial > hg > Members > nobuyasu > tightVNCClient
comparison src/myVncClient/MyVncClient.java @ 30:a335a1038a23
merge taninari's program
author | e085711 |
---|---|
date | Wed, 06 Jul 2011 12:30:17 +0900 |
parents | 750ecaa1e1b9 |
children | bf1126d1e721 |
comparison
equal
deleted
inserted
replaced
29:750ecaa1e1b9 | 30:a335a1038a23 |
---|---|
10 public class MyVncClient extends VncViewer implements | 10 public class MyVncClient extends VncViewer implements |
11 java.lang.Runnable, WindowListener { | 11 java.lang.Runnable, WindowListener { |
12 | 12 |
13 boolean inAnApplet = true; | 13 boolean inAnApplet = true; |
14 boolean inSeparateFrame = false; | 14 boolean inSeparateFrame = false; |
15 | 15 static Socket clientSocket = null; |
16 String parent,treenum; | |
17 Revalue value; //include trenumber, parentstnumber,etc | |
16 // | 18 // |
17 // main() is called when run as a java program from the command line. | 19 // main() is called when run as a java program from the command line. |
18 // It simply runs the applet inside a newly-created frame. | 20 // It simply runs the applet inside a newly-created frame. |
19 // | 21 // |
20 | 22 |
22 MyVncClient v = new MyVncClient(); | 24 MyVncClient v = new MyVncClient(); |
23 v.mainArgs = argv; | 25 v.mainArgs = argv; |
24 v.inAnApplet = false; | 26 v.inAnApplet = false; |
25 v.inSeparateFrame = true; | 27 v.inSeparateFrame = true; |
26 | 28 |
27 v.init(); | 29 v.init(null); |
28 v.start(); | 30 v.start(); |
29 } | 31 } |
30 | 32 |
31 | 33 |
32 | 34 |
33 // | 35 // |
34 // init() | 36 // init() |
35 // | 37 // |
36 | 38 |
37 public void init() { | 39 public void init(Revalue value) { |
38 | 40 |
39 readParameters(); | 41 // readParameters(); |
42 readParameters(value); | |
40 | 43 |
41 refApplet = this; | 44 refApplet = this; |
42 | 45 |
43 if (inSeparateFrame) { | 46 if (inSeparateFrame) { |
44 vncFrame = new Frame("TightVNC"); | 47 vncFrame = new Frame("TightVNC"); |
156 } | 159 } |
157 /*****************************************************************************/ | 160 /*****************************************************************************/ |
158 | 161 |
159 | 162 |
160 try { | 163 try { |
161 | |
162 if (showControls) | 164 if (showControls) |
163 buttonPanel.enableButtons(); | 165 buttonPanel.enableButtons(); |
164 | 166 |
165 moveFocusToDesktop(); | 167 moveFocusToDesktop(); |
166 | 168 |
173 } catch (ConnectException e) { | 175 } catch (ConnectException e) { |
174 fatalError("Network error: could not connect to server: " + host | 176 fatalError("Network error: could not connect to server: " + host |
175 + ":" + port, e); | 177 + ":" + port, e); |
176 } catch (EOFException e) { | 178 } catch (EOFException e) { |
177 | 179 |
178 //insert | 180 //insert |
179 echo = new echoClient(); | 181 //リーダーの子ノードがproxyに対して親が落ちたことを報告をする |
180 echo.openport(); | 182 if ("1".equals(echoClient.value.leaderflag)){ |
181 echo.losthost(); | 183 echo = new echoClient(); |
184 echo.openport(); | |
185 echo.losthost(); | |
186 } else if ("0".equals(echoClient.value.leaderflag)){ | |
187 try { | |
188 Thread.sleep(1000); | |
189 } catch (InterruptedException e1) { | |
190 // TODO Auto-generated catch block | |
191 e1.printStackTrace(); | |
192 } | |
193 echo = new echoClient(); | |
194 echo.openport(); | |
195 echo.losthost(); | |
196 }else{ | |
197 | |
182 | 198 |
183 if (showOfflineDesktop) { | 199 if (showOfflineDesktop) { |
184 e.printStackTrace(); | 200 e.printStackTrace(); |
185 System.out | 201 System.out |
186 .println("Network error: remote side closed connection"); | 202 .println("Network error: remote side closed connection"); |
201 } | 217 } |
202 } | 218 } |
203 } else { | 219 } else { |
204 fatalError("Network error: remote side closed connection", e); | 220 fatalError("Network error: remote side closed connection", e); |
205 } | 221 } |
222 } | |
206 } catch (IOException e) { | 223 } catch (IOException e) { |
207 String str = e.getMessage(); | 224 String str = e.getMessage(); |
208 if (str != null && str.length() != 0) { | 225 if (str != null && str.length() != 0) { |
209 fatalError("Network Error: " + str, e); | 226 fatalError("Network Error: " + str, e); |
210 } else { | 227 } else { |
640 // command line. On the command line, the arguments are just a sequence of | 657 // command line. On the command line, the arguments are just a sequence of |
641 // param_name/param_value pairs where the names and values correspond to | 658 // param_name/param_value pairs where the names and values correspond to |
642 // those expected in the html applet tag source. | 659 // those expected in the html applet tag source. |
643 // | 660 // |
644 | 661 |
645 void readParameters() { | 662 void readParameters(Revalue value) { |
646 if (mainArgs.length > 0){ | 663 /* |
647 host = mainArgs[0]; | 664 host = readParameter("HOST", !inAnApplet); |
648 echo = new echoClient(host); | 665 |
666 if (host == null) { host = getCodeBase().getHost(); if | |
667 (host.equals("")) { fatalError("HOST parameter not specified"); } } | |
668 | |
669 port = readIntParameter("PORT", 5550); | |
670 */ | |
671 | |
672 if(value==null){ | |
673 if(clientSocket==null) | |
674 { | |
675 echo = new echoClient(mainArgs[0]); | |
676 echo.openport(); | |
677 // value = echo.hostn(mainArgs[0]); | |
678 value = echo.hostn("1"); | |
649 }else{ | 679 }else{ |
650 host = "cls080.ie.u-ryukyu.ac.jp"; | 680 echo = new echoClient(); |
651 echo = new echoClient(); | 681 value = echo.Interruption(clientSocket); |
652 } | 682 } |
653 | 683 } |
654 | 684 //proxyからの返信で接続先を決定する |
655 if (mainArgs.length > 1) | 685 host=value.responseLine; |
656 port = Integer.parseInt(mainArgs[1]); | 686 parent=value.parent; |
657 else | 687 treenum=value.treenum; |
658 port = 5550; | 688 System.out.println("親は"+parent); |
659 | 689 System.out.println("自分の番号"+treenum); |
690 System.out.println("接続先hostは" + host); | |
691 | |
692 if (host == null) { | |
693 host = getCodeBase().getHost(); | |
694 if (host.equals("")) { | |
695 fatalError("HOST parameter not specified"); | |
696 } | |
697 } | |
698 port = 5550; | |
699 // Read "ENCPASSWORD" or "PASSWORD" parameter if specified. | |
660 readPasswordParameters(); | 700 readPasswordParameters(); |
661 | 701 |
662 String str; | 702 String str; |
663 if (inAnApplet) { | 703 if (inAnApplet) { |
664 str = readParameter("Open New Window", false); | 704 str = readParameter("Open New Window", false); |
975 public void windowIconified(WindowEvent evt) { | 1015 public void windowIconified(WindowEvent evt) { |
976 } | 1016 } |
977 | 1017 |
978 public void windowDeiconified(WindowEvent evt) { | 1018 public void windowDeiconified(WindowEvent evt) { |
979 } | 1019 } |
1020 public static void main(Socket _clientSocket) { | |
1021 // TODO Auto-generated method stub | |
1022 clientSocket = _clientSocket; | |
1023 MyVncClient v = new MyVncClient(); | |
1024 // v.mainArgs = argv; | |
1025 v.inAnApplet = false; | |
1026 v.inSeparateFrame = true; | |
1027 | |
1028 v.init(null); | |
1029 v.start(); | |
1030 } | |
1031 public static void main(Revalue value) { | |
1032 // TODO Auto-generated method stub | |
1033 MyVncClient v = new MyVncClient(); | |
1034 v.value = value; | |
1035 v.inAnApplet = false; | |
1036 v.inSeparateFrame = true; | |
1037 | |
1038 v.init(value); | |
1039 v.start(); | |
1040 | |
1041 } | |
980 } | 1042 } |
1043 |