comparison src/treeVnc/MyVncClient.java @ 22:24112133a0d9

add conf.txt src/treeVnc/ConfFileReader.java
author Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
date Fri, 20 Jan 2012 16:06:49 +0900
parents 578ea14c95e9
children b5c446990c0a
comparison
equal deleted inserted replaced
21:810c53d66376 22:24112133a0d9
1 package treeVnc; 1 package treeVnc;
2 2
3 import java.awt.*; 3 import java.awt.*;
4 import java.awt.event.*; 4 import java.awt.event.*;
5 import java.awt.image.BufferedImage;
6 import java.io.*; 5 import java.io.*;
7 import java.net.*; 6 import java.net.*;
8 import java.util.Random; 7 import java.util.Random;
9 8
10 import java.nio.ByteBuffer; 9 import java.nio.ByteBuffer;
19 private boolean inAnApplet = true; 18 private boolean inAnApplet = true;
20 private boolean inSeparateFrame = false; 19 private boolean inSeparateFrame = false;
21 private Socket clientSocket = null; 20 private Socket clientSocket = null;
22 private String parent, treenum; 21 private String parent, treenum;
23 private String leaderflag; 22 private String leaderflag;
24 private boolean runflag = false; 23 //private boolean runflag = false;
25 private boolean first = true; 24 private boolean first = true;
26 25
27 private EchoClient echoValue; 26 private EchoClient echoValue;
28 private int echoPort; 27 private int echoPort;
29 private String pHost; 28 private String pHost;
30 //private TextBox getHost; 29 private TextBoxClient getHost;
31 private GetBroadCastClient getBcast; 30 private GetBroadCastClient getBcast;
32 private Thread runBcast; 31 private Thread runBcast;
33 private BroadCastClient bCast; 32 private BroadCastClient bCast;
34 boolean isClient = false; 33 boolean isClient = false;
35 34
64 } catch (InterruptedException e) { 63 } catch (InterruptedException e) {
65 e.printStackTrace(); 64 e.printStackTrace();
66 } 65 }
67 if(mainArgs.length == 0) 66 if(mainArgs.length == 0)
68 getBcast.setStopFlag(true); 67 getBcast.setStopFlag(true);
69 68 else {
69 getHost = new TextBoxClient();
70 getHost.ipRegister();
71 }
72
73
70 if (mainArgs.length > 0) 74 if (mainArgs.length > 0)
71 pHost = mainArgs[0]; 75 pHost = getHost.getAddressOption();
76 //pHost = mainArgs[0];
72 else { 77 else {
73 pHost = getBcast.text.getAddress(); 78 pHost = getBcast.text.getAddress();
74 } 79 }
75 80
76 81
77 //pHost = "cls080.ie.u-ryukyu.ac.jp"; 82 //pHost = "cls080.ie.u-ryukyu.ac.jp";
78 if (mainArgs.length > 1) 83 if (mainArgs.length > 0)
79 port = Integer.parseInt(mainArgs[1]); 84 port = Integer.parseInt(getHost.getPortOption());
85 //port = Integer.parseInt(mainArgs[1]);
80 else { 86 else {
81 port = Integer.parseInt(getBcast.text.getPort()); 87 port = Integer.parseInt(getBcast.text.getPort());
82 getBcast.socketClose(); 88 getBcast.socketClose();
83 // port = 5999; 89 // port = 5999;
84 } 90 }
85 init(); 91 init();
86 start_threads(); 92 start_threads();
87 start(); 93 start();
88 } 94 }
89
90 //
91 // init()
92 //
93 95
94 public void init() { 96 public void init() {
95 97
96 readParameters(); 98 readParameters();
97 99
168 170
169 doProtocolInitialisation(); 171 doProtocolInitialisation();
170 172
171 createCanvas(0, 0); 173 createCanvas(0, 0);
172 174
173 // rfb.readPngData();
174 // vc.drawFirstImage();
175
176 } catch (IOException e) { 175 } catch (IOException e) {
177 try { 176 try {
178 rfb.sock.close(); 177 rfb.sock.close();
179 178
180 } catch (IOException e2) { 179 } catch (IOException e2) {
183 System.out.println("Socket error"); 182 System.out.println("Socket error");
184 // parent no find 183 // parent no find
185 Random rnd = new Random(); 184 Random rnd = new Random();
186 long ran = rnd.nextInt(3000) + 3000; 185 long ran = rnd.nextInt(3000) + 3000;
187 System.out.println(ran); 186 System.out.println(ran);
188 // 親がいない場合の処理はここに書く!!!! 187
189 /** 188 /**
190 * this while reconnection 189 * this while reconnection
191 */ 190 */
192 191
193 int counter = 0; 192 int counter = 0;
212 echoValue.openport(); 211 echoValue.openport();
213 echoValue.notfoundParent(); 212 echoValue.notfoundParent();
214 } 213 }
215 214
216 echoValue.openport(); 215 echoValue.openport();
217 /*
218 if(echoValue.notfoundParent()) {
219 break;
220 }
221 */
222 // runflag = echo.losthost();
223
224 216
225 if (echoValue.losthost()) { 217 if (echoValue.losthost()) {
226 break; 218 break;
227 } 219 }
228 220
229 counter++; 221 counter++;
230 } 222 }
231
232 // System.exit(0);
233 } catch (Exception e) { 223 } catch (Exception e) {
234 System.out.println(e); 224 System.out.println(e);
235 System.exit(0); 225 System.exit(0);
236 } 226 }
237
238 gbc.weightx = 1.0; 227 gbc.weightx = 1.0;
239 gbc.weighty = 1.0; 228 gbc.weighty = 1.0;
240 229
241 if (inSeparateFrame) { 230 if (inSeparateFrame) {
242
243 // Create a panel which itself is resizeable and can hold 231 // Create a panel which itself is resizeable and can hold
244 // non-resizeable VncCanvas component at the top left corner. 232 // non-resizeable VncCanvas component at the top left corner.
245 Panel canvasPanel = new Panel(); 233 Panel canvasPanel = new Panel();
246 canvasPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); 234 canvasPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
247 canvasPanel.add(vc); 235 canvasPanel.add(vc);
248
249 // Create a ScrollPane which will hold a panel with VncCanvas 236 // Create a ScrollPane which will hold a panel with VncCanvas
250 // inside. 237 // inside.
251 desktopScrollPane = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED); 238 desktopScrollPane = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED);
252 gbc.fill = GridBagConstraints.BOTH; 239 gbc.fill = GridBagConstraints.BOTH;
253 gridbag.setConstraints(desktopScrollPane, gbc); 240 gridbag.setConstraints(desktopScrollPane, gbc);
254 desktopScrollPane.add(canvasPanel); 241 desktopScrollPane.add(canvasPanel);
255
256 // Finally, add our ScrollPane to the Frame window. 242 // Finally, add our ScrollPane to the Frame window.
257 vncFrame.add(desktopScrollPane); 243 vncFrame.add(desktopScrollPane);
258 vncFrame.setTitle(rfb.desktopName); 244 vncFrame.setTitle(rfb.desktopName);
259 vncFrame.pack(); 245 vncFrame.pack();
260 vc.resizeDesktopFrame(); 246 vc.resizeDesktopFrame();
261 247 } else {
262 } else {
263
264 // Just add the VncCanvas component to the Applet. 248 // Just add the VncCanvas component to the Applet.
265 gridbag.setConstraints(vc, gbc); 249 gridbag.setConstraints(vc, gbc);
266 add(vc); 250 add(vc);
267 validate(); 251 validate();
268 252
295 echoValue.openport(); 279 echoValue.openport();
296 // runflag = echo.losthost(); 280 // runflag = echo.losthost();
297 if (echoValue.losthost()) { 281 if (echoValue.losthost()) {
298 break; 282 break;
299 } 283 }
284
300 } 285 }
301 } else { 286 } else {
302 287
303 if (showOfflineDesktop) { 288 if (showOfflineDesktop) {
304 e.printStackTrace(); 289 e.printStackTrace();
1252 vc.drawBufferedImage(b); 1237 vc.drawBufferedImage(b);
1253 }catch(IOException e){ 1238 }catch(IOException e){
1254 e.printStackTrace(); 1239 e.printStackTrace();
1255 } 1240 }
1256 } 1241 }
1242
1243 private boolean serverConfirm(String name,int port) {
1244 try{
1245 new Socket(name,port);
1246 return true;
1247 }
1248 catch (IOException e){
1249 return false;
1250 }
1251
1252 }
1257 1253
1258 } 1254 }