comparison src/myVncClient/MyVncClient.java @ 73:83acdeca0539

modify EchoClient
author e085711
date Tue, 30 Aug 2011 06:59:57 +0900
parents ec66d1d4dca0
children 7d25b08f5835
comparison
equal deleted inserted replaced
72:ec66d1d4dca0 73:83acdeca0539
3 import java.awt.*; 3 import java.awt.*;
4 import java.awt.event.*; 4 import java.awt.event.*;
5 import java.io.*; 5 import java.io.*;
6 import java.net.*; 6 import java.net.*;
7 import java.util.Random; 7 import java.util.Random;
8
9 import java.nio.ByteBuffer;
8 10
9 public class MyVncClient extends VncViewer implements InterfaceForViewer, java.lang.Runnable, 11 public class MyVncClient extends VncViewer implements InterfaceForViewer, java.lang.Runnable,
10 WindowListener { 12 WindowListener {
11 13
12 /** 14 /**
36 private void runClient(String[] argv) { 38 private void runClient(String[] argv) {
37 mainArgs = argv; 39 mainArgs = argv;
38 inAnApplet = false; 40 inAnApplet = false;
39 inSeparateFrame = true; 41 inSeparateFrame = true;
40 42
43 host = mainArgs[0];
44 port = Integer.parseInt(mainArgs[1]);
45
41 init(null); 46 init(null);
42 start_threads(); 47 start_threads();
43 start(); 48 start();
44 } 49 }
45 50
47 // init() 52 // init()
48 // 53 //
49 54
50 public void init(EchoClient value) { 55 public void init(EchoClient value) {
51 56
52 // getParentname(value); 57 readParameters();
53 readParameters(value);
54 // readParameters(); 58 // readParameters();
55 59
56 refApplet = this; 60 refApplet = this;
57 61
58 if (inSeparateFrame) { 62 if (inSeparateFrame) {
349 validate(); 353 validate();
350 } 354 }
351 355
352 showConnectionStatus("Connecting to " + host + ", port " + port + "..."); 356 showConnectionStatus("Connecting to " + host + ", port " + port + "...");
353 357
354 host = "localhost";
355 port = 5999;
356
357 rfb = new MyRfbProto(host, port, this); 358 rfb = new MyRfbProto(host, port, this);
358 showConnectionStatus("Connected to server"); 359 showConnectionStatus("Connected to server");
359 360
360 rfb.readVersionMsg(); 361 rfb.readVersionMsg();
361 showConnectionStatus("RFB server supports protocol version " 362 showConnectionStatus("RFB server supports protocol version "
362 + rfb.serverMajor + "." + rfb.serverMinor); 363 + rfb.serverMajor + "." + rfb.serverMinor);
363 364
365 rfb.writeVersionMsg();
366 showConnectionStatus("Using RFB protocol version " + rfb.clientMajor
367 + "." + rfb.clientMinor);
368
364 if(rfb.serverMinor == 998) { 369 if(rfb.serverMinor == 998) {
370 byte[] b = new byte[4];
371 b = rfb.readEchoPort();
372 int echoPort = castByteInt(b);
365 String h = host; 373 String h = host;
366 getParentname(echovalue); 374 getParentname(echovalue, echoPort);
367 if(h.equals(host)) { 375 if(h.equals(host)) {
368 rfb.changeParent(host, port); 376 rfb.changeParent(host, port);
369 rfb.readVersionMsg(); 377 rfb.readVersionMsg();
370 } 378 }
371 } 379 }
372 380
373 381
374 rfb.writeVersionMsg();
375 showConnectionStatus("Using RFB protocol version " + rfb.clientMajor
376 + "." + rfb.clientMinor);
377
378 int secType = rfb.negotiateSecurity(); 382 int secType = rfb.negotiateSecurity();
379 int authType; 383 int authType;
380 if (secType == RfbProto.SecTypeTight) { 384 if (secType == RfbProto.SecTypeTight) {
381 showConnectionStatus("Enabling TightVNC protocol extensions"); 385 showConnectionStatus("Enabling TightVNC protocol extensions");
382 rfb.setupTunneling(); 386 rfb.setupTunneling();
524 } 528 }
525 529
526 authPanel.moveFocusToDefaultField(); 530 authPanel.moveFocusToDefaultField();
527 String pw = authPanel.getPassword(); 531 String pw = authPanel.getPassword();
528 vncContainer.remove(authPanel); 532 vncContainer.remove(authPanel);
529
530 return pw; 533 return pw;
531 } 534 }
532 535
533 // 536 //
534 // Do the rest of the protocol initialisation. 537 // Do the rest of the protocol initialisation.
774 * command line. On the command line, the arguments are just a sequence of 777 * command line. On the command line, the arguments are just a sequence of
775 * param_name/param_value pairs where the names and values correspond to 778 * param_name/param_value pairs where the names and values correspond to
776 * those expected in the html applet tag source. 779 * those expected in the html applet tag source.
777 */ 780 */
778 781
779 void readParameters(EchoClient value) { 782 void readParameters() {
780 /* 783 /*
781 * host = readParameter("HOST", !inAnApplet); 784 * host = readParameter("HOST", !inAnApplet);
782 * 785 *
783 * if (host == null) { host = getCodeBase().getHost(); if 786 * if (host == null) { host = getCodeBase().getHost(); if
784 * (host.equals("")) { fatalError("HOST parameter not specified"); } } 787 * (host.equals("")) { fatalError("HOST parameter not specified"); } }
1099 } 1102 }
1100 1103
1101 public void windowDeiconified(WindowEvent evt) { 1104 public void windowDeiconified(WindowEvent evt) {
1102 } 1105 }
1103 1106
1104 void getParentname(EchoClient value) { 1107 void getParentname(EchoClient value, int echoPort) {
1105 if (value == null) { 1108 if (value == null) {
1106 1109
1107 if (clientSocket == null) { 1110 if (clientSocket == null) {
1108 String pHost; 1111 String pHost;
1109 if (mainArgs.length > 0) 1112 if (mainArgs.length > 0)
1110 pHost = mainArgs[0]; 1113 pHost = mainArgs[0];
1111 else 1114 else
1112 pHost = "cls080.ie.u-ryukyu.ac.jp"; 1115 pHost = "cls080.ie.u-ryukyu.ac.jp";
1113 echo = new EchoClient(pHost, this); 1116 // echo = new EchoClient(pHost, this);
1117 echo = new EchoClient(pHost, this, echoPort);
1114 echo.openport(); 1118 echo.openport();
1115 1119
1116 value = echo.hostn("1"); 1120 value = echo.hostn("1");
1117 } else { 1121 } else {
1118 echo = new EchoClient(); 1122 echo = new EchoClient();
1143 host = getCodeBase().getHost(); 1147 host = getCodeBase().getHost();
1144 if (host.equals("")) { 1148 if (host.equals("")) {
1145 fatalError("HOST parameter not specified"); 1149 fatalError("HOST parameter not specified");
1146 } 1150 }
1147 } 1151 }
1148 port = 5999; 1152 // port = 5999;
1149
1150 1153
1151 } 1154 }
1152 1155
1156 int castByteInt(byte[] b) {
1157 ByteBuffer bb = ByteBuffer.wrap(b);
1158 int value = bb.getInt();
1159 return value;
1160 }
1161
1162
1163
1153 public static void main(Socket _clientSocket) { 1164 public static void main(Socket _clientSocket) {
1154 MyVncClient v = new MyVncClient(); 1165 MyVncClient v = new MyVncClient();
1155 // v.clientSocket = _clientSocket; 1166 // v.clientSocket = _clientSocket;
1156 // v.mainArgs = argv; 1167 // v.mainArgs = argv;
1157 v.inAnApplet = false; 1168 v.inAnApplet = false;