# HG changeset patch # User e085711 # Date 1316493721 -32400 # Node ID 7a1e934144e6999f25b92ea79b03ffdc59f7d7c9 # Parent 3ea33e683522ff4589719f9161b977a627263074 modify RFB Protocol version 3.855. diff -r 3ea33e683522 -r 7a1e934144e6 src/myVncClient/CuiMyVncClient.java --- a/src/myVncClient/CuiMyVncClient.java Tue Sep 20 05:56:11 2011 +0900 +++ b/src/myVncClient/CuiMyVncClient.java Tue Sep 20 13:42:01 2011 +0900 @@ -316,22 +316,24 @@ + "." + rfb.clientMinor); - if(rfb.serverMinor == 855) { - byte[] b = new byte[4]; - b = rfb.readEchoPort(); - echoPort = castByteInt(b); + if (rfb.serverMinor == 855) { + boolean useEchoFlag = rfb.readProxyFlag(); + if (useEchoFlag) { + byte[] b = new byte[4]; + b = rfb.readEchoPort(); + echoPort = castByteInt(b); - InetAddress addr = InetAddress.getByName(pHost); - String h = new String(addr.getHostAddress()); - - getParentName(); - if(!(h.equals(host))) { - rfb.changeParent(host, port); - rfb.readVersionMsg(); - rfb.writeVersionMsg(); + InetAddress addr = InetAddress.getByName(pHost); + String h = new String(addr.getHostAddress()); + + getParentName(); + if (!(h.equals(host))) { + rfb.changeParent(host, port); + rfb.readVersionMsg(); + rfb.writeVersionMsg(); + } } - } - + } int secType = rfb.negotiateSecurity(); int authType; @@ -381,22 +383,24 @@ 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); + if (rfb.serverMinor == 855) { + boolean useEchoFlag = rfb.readProxyFlag(); + if (useEchoFlag) { + byte[] b = new byte[4]; + b = rfb.readEchoPort(); + echoPort = castByteInt(b); - InetAddress addr = InetAddress.getByName(host); - String h = new String(addr.getHostAddress()); - - getParentName(); - if(!(h.equals(host))) { - rfb.changeParent(host, port); - rfb.readVersionMsg(); - rfb.writeVersionMsg(); + InetAddress addr = InetAddress.getByName(pHost); + String h = new String(addr.getHostAddress()); + + getParentName(); + if (!(h.equals(host))) { + rfb.changeParent(host, port); + rfb.readVersionMsg(); + rfb.writeVersionMsg(); + } } - } - + } int secType = rfb.negotiateSecurity(); int authType; diff -r 3ea33e683522 -r 7a1e934144e6 src/myVncClient/MyRfbProto.java --- a/src/myVncClient/MyRfbProto.java Tue Sep 20 05:56:11 2011 +0900 +++ b/src/myVncClient/MyRfbProto.java Tue Sep 20 13:42:01 2011 +0900 @@ -61,6 +61,8 @@ private LinkedList cliListTmp; private LinkedList cliList; boolean createBimgFlag; + boolean proxyFlag = false; + //override InterfaceForViewer viewer; @@ -73,7 +75,7 @@ private int clients = 0; private Inflater inflater = new Inflater(); private Deflater deflater = new Deflater(); - + public MyRfbProto() throws IOException { } @@ -88,6 +90,16 @@ // executor = Executors.newSingleThreadExecutor(); } + MyRfbProto(String h, int p, MyVncClient v) throws IOException { + super(h, p, v); + cliList = new LinkedList(); + cliListTmp = new LinkedList(); + createBimgFlag = false; + proxyFlag = false; + // sendThreads = new LinkedList(); + // executor = Executors.newCachedThreadPool(); + // executor = Executors.newSingleThreadExecutor(); + } MyRfbProto(String h, int p) throws IOException { super(h, p); cliList = new LinkedList(); @@ -99,35 +111,27 @@ } + void sendProxyFlag(OutputStream os) throws IOException { + if(proxyFlag) os.write(1); + else os.write(0); + } - void readVersionMsg() throws Exception { - - byte[] b = new byte[12]; - - readFully(b); + boolean readProxyFlag() throws IOException{ + int flag = readU8(); + if(flag == 1) + return true; + else + return false; + } - if ((b[0] != 'R') || (b[1] != 'F') || (b[2] != 'B') || (b[3] != ' ') - || (b[4] < '0') || (b[4] > '9') || (b[5] < '0') || (b[5] > '9') - || (b[6] < '0') || (b[6] > '9') || (b[7] != '.') - || (b[8] < '0') || (b[8] > '9') || (b[9] < '0') || (b[9] > '9') - || (b[10] < '0') || (b[10] > '9') || (b[11] != '\n')) { - throw new Exception("Host " + host + " port " + port - + " is not an RFB server"); - } - - serverMajor = (b[4] - '0') * 100 + (b[5] - '0') * 10 + (b[6] - '0'); - serverMinor = (b[8] - '0') * 100 + (b[9] - '0') * 10 + (b[10] - '0'); - - if (serverMajor < 3) { - throw new Exception( - "RFB server does not support protocol version 3"); - } - - if (serverMinor == 855) { - - } - +/* + void sendPortNumber(OutputStream os) throws IOException { + byte[] b = new byte[4]; + b = castIntByte(geth.port); + os.write(b); } +*/ + byte[] readEchoPort() throws Exception { byte[] b = new byte[4]; readFully(b); @@ -265,11 +269,40 @@ } void sendRfbVersion(OutputStream os) throws IOException { -// os.write(versionMsg_3_855.getBytes()); - os.write(versionMsg_3_8.getBytes()); + os.write(versionMsg_3_855.getBytes()); +// os.write(versionMsg_3_8.getBytes()); } - void readVersionMsg(InputStream is) throws IOException { + int readVersionMsg(InputStream is, OutputStream os) throws IOException { + + byte[] b = new byte[12]; + + is.read(b); + + if ((b[0] != 'R') || (b[1] != 'F') || (b[2] != 'B') || (b[3] != ' ') + || (b[4] < '0') || (b[4] > '9') || (b[5] < '0') || (b[5] > '9') + || (b[6] < '0') || (b[6] > '9') || (b[7] != '.') + || (b[8] < '0') || (b[8] > '9') || (b[9] < '0') || (b[9] > '9') + || (b[10] < '0') || (b[10] > '9') || (b[11] != '\n')) { + throw new IOException("Host " + host + " port " + port + + " is not an RFB server"); + } + + int rfbMajor = (b[4] - '0') * 100 + (b[5] - '0') * 10 + (b[6] - '0'); + int rfbMinor = (b[8] - '0') * 100 + (b[9] - '0') * 10 + (b[10] - '0'); + + if (rfbMajor < 3) { + throw new IOException( + "RFB server does not support protocol version 3"); + } + + if (rfbMinor == 855) { + sendProxyFlag(os); +// if(proxyFlag)sendPortNumber(os); + } + return rfbMinor; + + } void readVersionMsg(InputStream is) throws IOException { byte[] b = new byte[12]; @@ -767,13 +800,22 @@ * initial connection of RFB protocol */ sendRfbVersion(os); - readVersionMsg(is); +// readVersionMsg(is); + int rfbMinor = readVersionMsg(is,os); sendSecurityType(os); readSecType(is); sendSecResult(os); readClientInit(is); sendInitData(os); new Thread(reader).start(); // discard incoming packet here after. + if(rfbMinor == 885){ + // send jpeg data of full screen. + + } else { + // send raw data of full screen. + + } + for (;;) { LinkedList bufs = c.poll(); int inputIndex = 0; diff -r 3ea33e683522 -r 7a1e934144e6 src/myVncClient/MyVncClient.java --- a/src/myVncClient/MyVncClient.java Tue Sep 20 05:56:11 2011 +0900 +++ b/src/myVncClient/MyVncClient.java Tue Sep 20 13:42:01 2011 +0900 @@ -8,8 +8,8 @@ import java.nio.ByteBuffer; -public class MyVncClient extends VncViewer implements InterfaceForViewer, java.lang.Runnable, - WindowListener { +public class MyVncClient extends VncViewer implements InterfaceForViewer, + java.lang.Runnable, WindowListener { /** * @@ -51,7 +51,7 @@ port = Integer.parseInt(mainArgs[1]); else port = 5999; - + init(); start_threads(); start(); @@ -129,7 +129,7 @@ accThread = new Thread(new AcceptThread(rfb, 5999)); accThread.start(); first = false; - }else { + } else { System.out.println("reConnectAndAuthenticate() "); reConnectAndAuthenticate(); accThread = new Thread(new AcceptThread(rfb, 5999)); @@ -144,10 +144,10 @@ // vc.drawFirstImage(); } catch (IOException e) { - try{ + try { rfb.sock.close(); - }catch(IOException e2){ + } catch (IOException e2) { e2.printStackTrace(); } System.out.println("Socket error"); @@ -161,17 +161,17 @@ */ int counter = 0; - vncFrame.setVisible(false); - vncFrame.dispose(); - + vncFrame.setVisible(false); + vncFrame.dispose(); + while (true) { /** * if my last node case reconnectoion stop */ echoValue = new EchoClient(echoValue, this); - //echoValue = new EchoClient(echoValue); - + // echoValue = new EchoClient(echoValue); + try { Thread.sleep(ran); } catch (InterruptedException e1) { @@ -190,7 +190,7 @@ } counter++; } - + // System.exit(0); } catch (Exception e) { System.out.println(e); @@ -246,13 +246,13 @@ fatalError("Network error: could not connect to server: " + host + ":" + port, e); } catch (EOFException e) { - + vncFrame.setVisible(false); vncFrame.dispose(); // num4 - if ( leaderflag != null) { + if (leaderflag != null) { while (true) { - //echoValue = new EchoClient(echoValue, this); + // echoValue = new EchoClient(echoValue, this); echoValue = new EchoClient(echoValue); echoValue.openport(); // runflag = echo.losthost(); @@ -378,24 +378,26 @@ showConnectionStatus("Using RFB protocol version " + rfb.clientMajor + "." + rfb.clientMinor); - - if(rfb.serverMinor == 855) { - byte[] b = new byte[4]; - b = rfb.readEchoPort(); - echoPort = castByteInt(b); + if (rfb.serverMinor == 855) { + boolean useEchoFlag = rfb.readProxyFlag(); + if (useEchoFlag) { + byte[] b = new byte[4]; + b = rfb.readEchoPort(); + echoPort = castByteInt(b); - InetAddress addr = InetAddress.getByName(pHost); - String h = new String(addr.getHostAddress()); - - getParentName(); - if(!(h.equals(host))) { - rfb.changeParent(host, port); - rfb.readVersionMsg(); - rfb.writeVersionMsg(); + InetAddress addr = InetAddress.getByName(pHost); + String h = new String(addr.getHostAddress()); + + getParentName(); + if (!(h.equals(host))) { + rfb.changeParent(host, port); + rfb.readVersionMsg(); + rfb.writeVersionMsg(); + boolean flag = rfb.readProxyFlag(); + } } } - int secType = rfb.negotiateSecurity(); int authType; if (secType == RfbProto.SecTypeTight) { @@ -434,7 +436,7 @@ vncFrame.setVisible(true); } else { validate(); - } + } showConnectionStatus("Connecting to " + host + ", port " + port + "..."); @@ -450,24 +452,24 @@ showConnectionStatus("Using RFB protocol version " + rfb.clientMajor + "." + rfb.clientMinor); - - if(rfb.serverMinor == 855) { - byte[] b = new byte[4]; - b = rfb.readEchoPort(); - echoPort = castByteInt(b); + if (rfb.serverMinor == 855) { + boolean useEchoFlag = rfb.readProxyFlag(); + if (useEchoFlag) { + byte[] b = new byte[4]; + b = rfb.readEchoPort(); + echoPort = castByteInt(b); - InetAddress addr = InetAddress.getByName(host); - String h = new String(addr.getHostAddress()); - - getParentName(); - if(!(h.equals(host))) { - rfb.changeParent(host, port); - rfb.readVersionMsg(); - rfb.writeVersionMsg(); + InetAddress addr = InetAddress.getByName(pHost); + String h = new String(addr.getHostAddress()); + + getParentName(); + if (!(h.equals(host))) { + rfb.changeParent(host, port); + rfb.readVersionMsg(); + rfb.writeVersionMsg(); + } } } - - int secType = rfb.negotiateSecurity(); int authType; if (secType == RfbProto.SecTypeTight) { @@ -495,7 +497,8 @@ default: throw new Exception("Unknown authentication scheme " + authType); } - } + } + // // Show a message describing the connection status. // To hide the connection status label, use (msg == null). @@ -823,7 +826,7 @@ * * port = readIntParameter("PORT", 5550); */ - + // Read "ENCPASSWORD" or "PASSWORD" parameter if specified. readPasswordParameters(); @@ -1027,7 +1030,7 @@ System.exit(1); } } - + // // Show message text and optionally "Relogin" and "Close" buttons. // @@ -1138,7 +1141,7 @@ public void windowDeiconified(WindowEvent evt) { } - + public void getParentName() { if (echoValue == null) { @@ -1177,6 +1180,7 @@ public void setEchoValue(EchoClient value) { this.echoValue = value; } + int castByteInt(byte[] b) { ByteBuffer bb = ByteBuffer.wrap(b); int value = bb.getInt(); @@ -1186,12 +1190,11 @@ public void setClientSocket(Socket sock) { clientSocket = sock; } - + public void close() { rfb.close(); vncFrame.setVisible(false); vncFrame.dispose(); } - }