Mercurial > hg > Members > nobuyasu > tightVNCProxy
changeset 180:da276538c1d5
modify VncProxyService.java
author | e085711 |
---|---|
date | Tue, 25 Oct 2011 01:41:05 +0900 |
parents | 0f0d3193017c |
children | f0dc6e6e85dc |
files | src/myVncProxy/MyRfbProto.java src/myVncProxy/VncProxyService.java |
diffstat | 2 files changed, 145 insertions(+), 167 deletions(-) [+] |
line wrap: on
line diff
--- a/src/myVncProxy/MyRfbProto.java Tue Oct 25 01:05:49 2011 +0900 +++ b/src/myVncProxy/MyRfbProto.java Tue Oct 25 01:41:05 2011 +0900 @@ -141,16 +141,15 @@ void authenticationRequestAccess() throws IOException { - byte[] inBuf = new byte[260]; - int i = 0; - readFully(inBuf); + byte[] inBuf = new byte[300]; + is.read(inBuf); byte[] outBuf = new byte[256]; os.write(outBuf); os.flush(); int result = readU32(); - if(result == 1) { + if(result != 0) { System.out.println("faild authentication "); throw new IOException(); }
--- a/src/myVncProxy/VncProxyService.java Tue Oct 25 01:05:49 2011 +0900 +++ b/src/myVncProxy/VncProxyService.java Tue Oct 25 01:41:05 2011 +0900 @@ -1,4 +1,5 @@ package myVncProxy; + import java.awt.*; import java.awt.event.*; import java.io.*; @@ -9,27 +10,27 @@ public static void main(String[] argv) { VncProxyService v = new VncProxyService(); - //v.checkArgs(argv); - + // v.checkArgs(argv); + v.mainArgs = argv; v.init(); v.start_threads(); } - + String[] mainArgs; String username; - - CreateHtmlFile htmlFile; + + CreateHtmlFile hgtmlFile; // RfbProto rfb; MyRfbProto rfb; Thread rfbThread; Thread accThread; Thread clientThread; - CreateThread geth; - AcceptClient acc; - private TextBox getHost; + CreateThread geth; + AcceptClient acc; + private TextBox getHost; Frame vncFrame; Container vncContainer; @@ -38,7 +39,7 @@ ButtonPanel buttonPanel; Label connStatusLabel; ProxyVncCanvas vc; -// OptionsFrame options; + // OptionsFrame options; OptionsNoFrame options; ClipboardFrame clipboard; RecordingFrame rec; @@ -69,28 +70,28 @@ String url; -// XmlRpc client; + // XmlRpc client; String wpUsername, wpPassword, blogId; String title = "TreeVNC"; - - void checkArgs(String[] argv){ + + void checkArgs(String[] argv) { int len = argv.length; - for(int i = 0; i < len ; i ++) { + for (int i = 0; i < len; i++) { String str = argv[i]; - if (str.equals("-h") || str.equals("--host")){ + if (str.equals("-h") || str.equals("--host")) { host = argv[++i]; - } else if (str.equals("-pn") || str.equals("--port")){ + } else if (str.equals("-pn") || str.equals("--port")) { port = Integer.parseInt(argv[++i]); - } else if (str.equals("-pw") || str.equals("--password")){ + } else if (str.equals("-pw") || str.equals("--password")) { passwordParam = argv[++i]; - } else if (str.equals("-w") || str.equals("--wpurl")){ + } else if (str.equals("-w") || str.equals("--wpurl")) { url = argv[++i]; - } else if (str.equals("-wu") || str.equals("--wpusername")){ + } else if (str.equals("-wu") || str.equals("--wpusername")) { wpUsername = argv[++i]; - } else if (str.equals("-wp") || str.equals("--wppassword")){ + } else if (str.equals("-wp") || str.equals("--wppassword")) { wpPassword = argv[++i]; - } else if (str.equals("-wb") || str.equals("--wpblogId")){ + } else if (str.equals("-wb") || str.equals("--wpblogId")) { blogId = argv[++i]; } else if (str.equals("--help")) { printHelp(); @@ -99,20 +100,22 @@ host = argv[0]; port = Integer.parseInt(argv[1]); passwordParam = argv[2]; - } else if (len <= 2) { + } else if (len == 2) { host = argv[0]; port = Integer.parseInt(argv[1]); + } else if (len == 1) { + host = argv[0]; } } - - } - + } + void printHelp() { - System.out.println("usage: java -jar VncProxyService [-h hostname] " + - "[-pn portnumber] [-pw password] [-w WordPressURL] [-wu WPUsername] " + - "[-wp WPPassword] [-wb blogId]"); + System.out + .println("usage: java -jar VncProxyService [-h hostname] " + + "[-pn portnumber] [-pw password] [-w WordPressURL] [-wu WPUsername] " + + "[-wp WPPassword] [-wb blogId]"); } - + // // init() // @@ -120,7 +123,7 @@ public void init() { readParameters(); - + options = new OptionsNoFrame(this); recordingSync = new Object(); @@ -130,56 +133,53 @@ cursorUpdatesDef = null; eightBitColorsDef = null; - try{ + try { connectAndAuthenticate(); doProtocolInitialisation(); - }catch (NoRouteToHostException e) { + } catch (NoRouteToHostException e) { fatalError("Network error: no route to server: " + host, e); } catch (UnknownHostException e) { fatalError("Network error: server name unknown: " + host, e); } catch (ConnectException e) { fatalError("Network error: could not connect to server: " + host + ":" + port, e); - }catch(Exception e){} - + } catch (IOException e) { + fatalError("Network error: faild connect or authenticate to server"); + } catch (Exception e) { + + } + rfb.selectPort(5999); rfbThread = new Thread(this); - accThread = new Thread(new AcceptThread(rfb, 5999)); - -/* - if(url != null) { - try { - client = new XmlRpc(blogId, wpUsername, wpPassword, url ); - InetAddress addr = InetAddress.getLocalHost(); - String add = new String(addr.getHostAddress()); - client.addDescription(rfb.desktopName); - setStatusXmlRpc(client, title, add, rfb.acceptPort); - client.editPost(); - System.out.println("URL:\n" + client.getUrl() + "\n"); - } catch (MalformedURLException e) { - System.out.println("Faild create instance of class XmlRpc"); - e.printStackTrace(); - } catch (UnknownHostException e) { - e.printStackTrace(); - } - } -*/ - - + accThread = new Thread(new AcceptThread(rfb, 5999)); + + /* + * if(url != null) { try { client = new XmlRpc(blogId, wpUsername, + * wpPassword, url ); InetAddress addr = InetAddress.getLocalHost(); + * String add = new String(addr.getHostAddress()); + * client.addDescription(rfb.desktopName); setStatusXmlRpc(client, + * title, add, rfb.acceptPort); client.editPost(); + * System.out.println("URL:\n" + client.getUrl() + "\n"); } catch + * (MalformedURLException e) { + * System.out.println("Faild create instance of class XmlRpc"); + * e.printStackTrace(); } catch (UnknownHostException e) { + * e.printStackTrace(); } } + */ + } -/* - void setStatusXmlRpc(XmlRpc client, String title, String hostname, int port) { - client.setTitle(title); - String description = makeDescription(hostname, Integer.toString(port)); - client.addDescription(description); - } -*/ + + /* + * void setStatusXmlRpc(XmlRpc client, String title, String hostname, int + * port) { client.setTitle(title); String description = + * makeDescription(hostname, Integer.toString(port)); + * client.addDescription(description); } + */ String makeDescription(String hostname, String port) { String description = "<h1>" + hostname + " " + port + "<h1>\n"; return description; } - - public void start_threads(){ + + public void start_threads() { rfbThread.start(); accThread.start(); rfb.requestThreadStart(); @@ -193,15 +193,15 @@ public void run() { try { -// connectAndAuthenticate(); -// doProtocolInitialisation(); -/* - htmlFile = new CreateHtmlFile(rfb, host, username); - htmlFile.createHtml(); -*/ + // connectAndAuthenticate(); + // doProtocolInitialisation(); + /* + * htmlFile = new CreateHtmlFile(rfb, host, username); + * htmlFile.createHtml(); + */ vc = new ProxyVncCanvas(this, 0, 0); vc.updateFramebufferSize(); - + processNormalProtocol();// main loop } catch (NoRouteToHostException e) { @@ -234,7 +234,7 @@ } else { fatalError(e.toString(), e); } - } catch (Exception e) { + } catch (Exception e) { String str = e.getMessage(); if (str != null && str.length() != 0) { fatalError("Error: " + str, e); @@ -269,15 +269,14 @@ // void connectAndAuthenticate() throws Exception { - if(mainArgs.length==0) - acc = new AcceptClient(getHost.getAddress()); - //acc = new AcceptClient(); + if (mainArgs.length == 0) + acc = new AcceptClient(getHost.getAddress()); + // acc = new AcceptClient(); else - acc = new AcceptClient(mainArgs[0]); - geth = new CreateThread(acc , echoPort); - Thread thread = new Thread(geth); - thread.start(); - + acc = new AcceptClient(mainArgs[0]); + geth = new CreateThread(acc, echoPort); + Thread thread = new Thread(geth); + thread.start(); showConnectionStatus("Initializing..."); @@ -343,22 +342,21 @@ String askPassword() throws Exception { /* - * showConnectionStatus(null); - * AuthPanel authPanel = new AuthPanel(this); + * showConnectionStatus(null); AuthPanel authPanel = new + * AuthPanel(this); * * GridBagConstraints gbc = new GridBagConstraints(); gbc.gridwidth = * GridBagConstraints.REMAINDER; gbc.anchor = * GridBagConstraints.NORTHWEST; gbc.weightx = 1.0; gbc.weighty = 1.0; * gbc.ipadx = 100; gbc.ipady = 50; gridbag.setConstraints(authPanel, * gbc); vncContainer.add(authPanel); - - - authPanel.moveFocusToDefaultField(); - vncContainer.remove(authPanel); + * + * + * authPanel.moveFocusToDefaultField(); vncContainer.remove(authPanel); */ showConnectionStatus("ask password..."); String pw; - if(mainArgs.length!=0) + if (mainArgs.length != 0) pw = mainArgs[2]; else pw = getHost.getPassword(); @@ -373,14 +371,13 @@ rfb.writeClientInit(); rfb.readServerInit(); - System.out.println("Desktop name is " + rfb.desktopName); System.out.println("Desktop size is " + rfb.framebufferWidth + " x " + rfb.framebufferHeight); setEncodings(); - //showConnectionStatus(null); + // showConnectionStatus(null); } // @@ -405,30 +402,24 @@ int preferredEncoding = options.preferredEncoding; if (preferredEncoding == -1) { long kbitsPerSecond = rfb.kbitsPerSecond(); -/* - if (nEncodingsSaved < 1) { - // Choose Tight or ZRLE encoding for the very first update. - System.out.println("Using Tight/ZRLE encodings"); - preferredEncoding = RfbProto.EncodingTight; - } else if (kbitsPerSecond > 2000 - && encodingsSaved[0] != RfbProto.EncodingHextile) { - // Switch to Hextile if the connection speed is above 2Mbps. - System.out.println("Throughput " + kbitsPerSecond - + " kbit/s - changing to Hextile encoding"); - preferredEncoding = RfbProto.EncodingHextile; - } else if (kbitsPerSecond < 1000 - && encodingsSaved[0] != RfbProto.EncodingTight) { - // Switch to Tight/ZRLE if the connection speed is below 1Mbps. - System.out.println("Throughput " + kbitsPerSecond - + " kbit/s - changing to Tight/ZRLE encodings"); - preferredEncoding = RfbProto.EncodingTight; - } else { - // Don't change the encoder. - if (autoSelectOnly) - return; - preferredEncoding = encodingsSaved[0]; - } -*/ + /* + * if (nEncodingsSaved < 1) { // Choose Tight or ZRLE encoding for + * the very first update. + * System.out.println("Using Tight/ZRLE encodings"); + * preferredEncoding = RfbProto.EncodingTight; } else if + * (kbitsPerSecond > 2000 && encodingsSaved[0] != + * RfbProto.EncodingHextile) { // Switch to Hextile if the + * connection speed is above 2Mbps. System.out.println("Throughput " + * + kbitsPerSecond + " kbit/s - changing to Hextile encoding"); + * preferredEncoding = RfbProto.EncodingHextile; } else if + * (kbitsPerSecond < 1000 && encodingsSaved[0] != + * RfbProto.EncodingTight) { // Switch to Tight/ZRLE if the + * connection speed is below 1Mbps. System.out.println("Throughput " + * + kbitsPerSecond + " kbit/s - changing to Tight/ZRLE encodings"); + * preferredEncoding = RfbProto.EncodingTight; } else { // Don't + * change the encoder. if (autoSelectOnly) return; preferredEncoding + * = encodingsSaved[0]; } + */ } else { // Auto encoder selection is not enabled. if (autoSelectOnly) @@ -438,54 +429,43 @@ int[] encodings = new int[20]; int nEncodings = 0; - encodings[nEncodings++] = preferredEncoding; if (options.useCopyRect) { encodings[nEncodings++] = RfbProto.EncodingCopyRect; } -/* - if (preferredEncoding != RfbProto.EncodingTight) { - encodings[nEncodings++] = RfbProto.EncodingTight; - } -*/ + /* + * if (preferredEncoding != RfbProto.EncodingTight) { + * encodings[nEncodings++] = RfbProto.EncodingTight; } + */ if (preferredEncoding != RfbProto.EncodingZRLE) { encodings[nEncodings++] = RfbProto.EncodingZRLE; } -/* - if (preferredEncoding != RfbProto.EncodingHextile) { - encodings[nEncodings++] = RfbProto.EncodingHextile; - } - if (preferredEncoding != RfbProto.EncodingZlib) { - encodings[nEncodings++] = RfbProto.EncodingZlib; - } -*/ -/* - if (preferredEncoding != RfbProto.EncodingCoRRE) { - encodings[nEncodings++] = RfbProto.EncodingCoRRE; - } - if (preferredEncoding != RfbProto.EncodingRRE) { - encodings[nEncodings++] = RfbProto.EncodingRRE; - } -*/ -/* - if (options.compressLevel >= 0 && options.compressLevel <= 9) { - encodings[nEncodings++] = RfbProto.EncodingCompressLevel0 - + options.compressLevel; - } - if (options.jpegQuality >= 0 && options.jpegQuality <= 9) { - encodings[nEncodings++] = RfbProto.EncodingQualityLevel0 - + options.jpegQuality; - } - if (options.requestCursorUpdates) { - encodings[nEncodings++] = RfbProto.EncodingXCursor; - encodings[nEncodings++] = RfbProto.EncodingRichCursor; - if (!options.ignoreCursorUpdates) - encodings[nEncodings++] = RfbProto.EncodingPointerPos; - } - */ - + /* + * if (preferredEncoding != RfbProto.EncodingHextile) { + * encodings[nEncodings++] = RfbProto.EncodingHextile; } if + * (preferredEncoding != RfbProto.EncodingZlib) { + * encodings[nEncodings++] = RfbProto.EncodingZlib; } + */ + /* + * if (preferredEncoding != RfbProto.EncodingCoRRE) { + * encodings[nEncodings++] = RfbProto.EncodingCoRRE; } if + * (preferredEncoding != RfbProto.EncodingRRE) { encodings[nEncodings++] + * = RfbProto.EncodingRRE; } + */ + /* + * if (options.compressLevel >= 0 && options.compressLevel <= 9) { + * encodings[nEncodings++] = RfbProto.EncodingCompressLevel0 + + * options.compressLevel; } if (options.jpegQuality >= 0 && + * options.jpegQuality <= 9) { encodings[nEncodings++] = + * RfbProto.EncodingQualityLevel0 + options.jpegQuality; } if + * (options.requestCursorUpdates) { encodings[nEncodings++] = + * RfbProto.EncodingXCursor; encodings[nEncodings++] = + * RfbProto.EncodingRichCursor; if (!options.ignoreCursorUpdates) + * encodings[nEncodings++] = RfbProto.EncodingPointerPos; } + */ + encodings[nEncodings++] = RfbProto.EncodingLastRect; encodings[nEncodings++] = RfbProto.EncodingNewFBSize; @@ -503,7 +483,7 @@ if (encodingsWereChanged) { try { - rfb.writeSetEncodings(encodings, nEncodings); + rfb.writeSetEncodings(encodings, nEncodings); if (vc != null) { vc.softCursorFree(); } @@ -623,24 +603,23 @@ // void readParameters() { - if(mainArgs.length==0){ + if (mainArgs.length == 0) { getHost = new TextBox(); getHost.ipRegister(); host = getHost.getAddress(); } else { host = mainArgs[0]; } - - if(mainArgs.length < 2){ + + if (mainArgs.length < 2) { port = Integer.parseInt(getHost.getPort()); -// port = 5900; - }else{ + // port = 5900; + } else { port = Integer.parseInt(mainArgs[1]); } - // Read "ENCPASSWORD" or "PASSWORD" parameter if specified. -// readPasswordParameters(); + // readPasswordParameters(); String str; @@ -685,7 +664,7 @@ private void readPasswordParameters() { String encPasswordParam; // String encPasswordParam = readParameter("ENCPASSWORD", false); - if(mainArgs.length!=0) + if (mainArgs.length != 0) encPasswordParam = mainArgs[2]; else encPasswordParam = getHost.getPassword(); @@ -781,7 +760,7 @@ if (rfb != null && !rfb.closed()) rfb.close(); -// options.dispose(); + // options.dispose(); clipboard.dispose(); if (rec != null) rec.dispose(); @@ -867,7 +846,7 @@ System.out.println("Destroying applet"); vncContainer.removeAll(); -// options.dispose(); + // options.dispose(); clipboard.dispose(); if (rec != null) rec.dispose();