# HG changeset patch # User e085711 # Date 1309919490 -32400 # Node ID 68f0bc9c4211ff99885b313a434f093447a9cd44 # Parent 53c831c3a5136d7ad039ebc71b4271e2b12bf93c modify MyRfbProto.java and acceptThread.java diff -r 53c831c3a513 -r 68f0bc9c4211 src/myVncClient/MyRfbProto.java --- a/src/myVncClient/MyRfbProto.java Thu Jun 23 07:59:55 2011 +0900 +++ b/src/myVncClient/MyRfbProto.java Wed Jul 06 11:31:30 2011 +0900 @@ -68,7 +68,7 @@ executor = Executors.newSingleThreadExecutor(); } - // override + // over write void writeVersionMsg() throws IOException { clientMajor = 3; if (serverMinor >= 9) { @@ -192,6 +192,30 @@ void sendRfbVersion(OutputStream os) throws IOException{ os.write(versionMsg_3_998.getBytes()); } + void readVersionMsg(InputStream is) 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"); + } + + 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 IOException( + "RFB server does not support protocol version 3"); + } + + } void sendSecurityType(OutputStream os) throws IOException { // number-of-security-types os.write(1); @@ -199,6 +223,16 @@ // 1:None os.write(1); } + void readSecType(InputStream is) throws IOException { + byte[] b = new byte[1]; + is.read(b); + + } + void sendSecResult(OutputStream os) throws IOException { + byte[] b = castIntByte(0); + os.write(b); + } + void readClientInit(InputStream in) throws IOException { byte[] b = new byte[0]; in.read(b); diff -r 53c831c3a513 -r 68f0bc9c4211 src/myVncClient/acceptThread.java --- a/src/myVncClient/acceptThread.java Thu Jun 23 07:59:55 2011 +0900 +++ b/src/myVncClient/acceptThread.java Wed Jul 06 11:31:30 2011 +0900 @@ -19,7 +19,10 @@ OutputStream os = newCli.getOutputStream(); InputStream is = newCli.getInputStream(); rfb.sendRfbVersion(os); + rfb.readVersionMsg(is); rfb.sendSecurityType(os); + rfb.readSecType(is); + rfb.sendSecResult(os); rfb.readClientInit(is); rfb.sendInitData(os); rfb.createBimgFlag = true;