# HG changeset patch # User e085711 # Date 1314655197 -32400 # Node ID 83acdeca0539da146826f897b7600df58080bb68 # Parent ec66d1d4dca06823afbdf5474016b04d24e065e4 modify EchoClient diff -r ec66d1d4dca0 -r 83acdeca0539 src/myVncClient/EchoClient.java --- a/src/myVncClient/EchoClient.java Mon Aug 29 03:14:53 2011 +0900 +++ b/src/myVncClient/EchoClient.java Tue Aug 30 06:59:57 2011 +0900 @@ -20,6 +20,8 @@ Socket clientSocket = null; // MyVncClient client; InterfaceForViewer client; + int echoPort = 9999; + // WaitReplyに自分自身を渡している public EchoClient() { @@ -30,6 +32,13 @@ this.client = client; name = _name; } + + public EchoClient(String _name,MyVncClient client, int echoPort) { + this.client = client; + name = _name; + this.echoPort = echoPort; + } + public EchoClient(EchoClient echo,MyVncClient client) { this.client = client; @@ -63,9 +72,9 @@ // ポート9999番に接続 try { if (name != null) { - echoSocket = new Socket(name, 9999); + echoSocket = new Socket(name, echoPort); } else { - echoSocket = new Socket("133.13.48.18", 9999); + echoSocket = new Socket("133.13.48.18", echoPort); } os = new DataOutputStream(echoSocket.getOutputStream()); is = new BufferedReader(new InputStreamReader(echoSocket.getInputStream())); diff -r ec66d1d4dca0 -r 83acdeca0539 src/myVncClient/MyRfbProto.java --- a/src/myVncClient/MyRfbProto.java Mon Aug 29 03:14:53 2011 +0900 +++ b/src/myVncClient/MyRfbProto.java Tue Aug 30 06:59:57 2011 +0900 @@ -126,6 +126,14 @@ } } + byte[] readEchoPort() throws Exception { + byte[] b = new byte[4]; + readFully(b); + + return b; + } + + void changeParent(String h, int p) throws IOException { host = h; @@ -284,8 +292,10 @@ "RFB server does not support protocol version 3"); } + } + void sendSecurityType(OutputStream os) throws IOException { // number-of-security-types os.write(1); diff -r ec66d1d4dca0 -r 83acdeca0539 src/myVncClient/MyVncClient.java --- a/src/myVncClient/MyVncClient.java Mon Aug 29 03:14:53 2011 +0900 +++ b/src/myVncClient/MyVncClient.java Tue Aug 30 06:59:57 2011 +0900 @@ -6,6 +6,8 @@ import java.net.*; import java.util.Random; +import java.nio.ByteBuffer; + public class MyVncClient extends VncViewer implements InterfaceForViewer, java.lang.Runnable, WindowListener { @@ -38,6 +40,9 @@ inAnApplet = false; inSeparateFrame = true; + host = mainArgs[0]; + port = Integer.parseInt(mainArgs[1]); + init(null); start_threads(); start(); @@ -49,8 +54,7 @@ public void init(EchoClient value) { -// getParentname(value); - readParameters(value); + readParameters(); // readParameters(); refApplet = this; @@ -351,9 +355,6 @@ showConnectionStatus("Connecting to " + host + ", port " + port + "..."); - host = "localhost"; - port = 5999; - rfb = new MyRfbProto(host, port, this); showConnectionStatus("Connected to server"); @@ -361,9 +362,16 @@ showConnectionStatus("RFB server supports protocol version " + rfb.serverMajor + "." + rfb.serverMinor); + rfb.writeVersionMsg(); + showConnectionStatus("Using RFB protocol version " + rfb.clientMajor + + "." + rfb.clientMinor); + if(rfb.serverMinor == 998) { + byte[] b = new byte[4]; + b = rfb.readEchoPort(); + int echoPort = castByteInt(b); String h = host; - getParentname(echovalue); + getParentname(echovalue, echoPort); if(h.equals(host)) { rfb.changeParent(host, port); rfb.readVersionMsg(); @@ -371,10 +379,6 @@ } - rfb.writeVersionMsg(); - showConnectionStatus("Using RFB protocol version " + rfb.clientMajor - + "." + rfb.clientMinor); - int secType = rfb.negotiateSecurity(); int authType; if (secType == RfbProto.SecTypeTight) { @@ -526,7 +530,6 @@ authPanel.moveFocusToDefaultField(); String pw = authPanel.getPassword(); vncContainer.remove(authPanel); - return pw; } @@ -776,7 +779,7 @@ * those expected in the html applet tag source. */ - void readParameters(EchoClient value) { + void readParameters() { /* * host = readParameter("HOST", !inAnApplet); * @@ -1101,7 +1104,7 @@ public void windowDeiconified(WindowEvent evt) { } - void getParentname(EchoClient value) { + void getParentname(EchoClient value, int echoPort) { if (value == null) { if (clientSocket == null) { @@ -1110,7 +1113,8 @@ pHost = mainArgs[0]; else pHost = "cls080.ie.u-ryukyu.ac.jp"; - echo = new EchoClient(pHost, this); +// echo = new EchoClient(pHost, this); + echo = new EchoClient(pHost, this, echoPort); echo.openport(); value = echo.hostn("1"); @@ -1145,11 +1149,18 @@ fatalError("HOST parameter not specified"); } } - port = 5999; - +// port = 5999; - } + } + int castByteInt(byte[] b) { + ByteBuffer bb = ByteBuffer.wrap(b); + int value = bb.getInt(); + return value; + } + + + public static void main(Socket _clientSocket) { MyVncClient v = new MyVncClient(); // v.clientSocket = _clientSocket; diff -r ec66d1d4dca0 -r 83acdeca0539 src/myVncClient/VncViewer.java --- a/src/myVncClient/VncViewer.java Mon Aug 29 03:14:53 2011 +0900 +++ b/src/myVncClient/VncViewer.java Tue Aug 30 06:59:57 2011 +0900 @@ -674,7 +674,8 @@ host = readParameter("HOST", !inAnApplet); - if (host == null) { host = getCodeBase().getHost(); + if (host == null) { + host = getCodeBase().getHost(); if (host.equals("")) { fatalError("HOST parameter not specified"); }