annotate src/main/java/jp/ac/u_ryukyu/treevnc/TreeVncCommandChannelListener.java @ 231:0e0e6744432c

get new nodeList for checkDelay.
author oc
date Wed, 08 Oct 2014 17:44:39 +0900
parents 3189e210a7ed
children d655db005535
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
31
872d9bcbfe56 Before changing the Viewer.
one
parents: 17
diff changeset
1 package jp.ac.u_ryukyu.treevnc;
204
d9d234715853 TreeManager for each interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 169
diff changeset
2 import java.net.InetAddress;
d9d234715853 TreeManager for each interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 169
diff changeset
3 import java.net.NetworkInterface;
11
57ae9fbb1245 add files
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 import java.net.Socket;
157
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
5 import java.nio.ByteBuffer;
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
6 import java.nio.ByteOrder;
160
b9052986bbb3 fix command loop.
oc
parents: 159
diff changeset
7 import java.util.concurrent.LinkedBlockingQueue;
b9052986bbb3 fix command loop.
oc
parents: 159
diff changeset
8 import java.util.concurrent.TimeUnit;
157
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
9 import java.io.IOException;
11
57ae9fbb1245 add files
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 import java.io.InputStream;
57ae9fbb1245 add files
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 import java.io.OutputStream;
57ae9fbb1245 add files
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12
157
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
13 import com.glavsoft.exceptions.TransportException;
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
14 import com.glavsoft.rfb.protocol.ProtocolContext;
159
1c9f6acdfeb2 TreeCommand enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 157
diff changeset
15 import com.glavsoft.rfb.protocol.ProtocolContext.TreeCommand;
157
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
16 import com.glavsoft.rfb.protocol.state.HandshakeState;
17
718cdde720d4 add setInitData()
one
parents: 12
diff changeset
17 import com.glavsoft.transport.Reader;
718cdde720d4 add setInitData()
one
parents: 12
diff changeset
18 import com.glavsoft.transport.Writer;
718cdde720d4 add setInitData()
one
parents: 12
diff changeset
19
231
0e0e6744432c get new nodeList for checkDelay.
oc
parents: 223
diff changeset
20
157
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
21 public class TreeVncCommandChannelListener implements Runnable {
207
b31903e5b02d rename myRFBProto
oc
parents: 204
diff changeset
22 public TreeRFBProto rfb = null;
157
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
23 byte[] imageBytes;
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
24 int port;
160
b9052986bbb3 fix command loop.
oc
parents: 159
diff changeset
25 LinkedBlockingQueue<TreeVncCommand> cmdQueue = new LinkedBlockingQueue<TreeVncCommand>();
159
1c9f6acdfeb2 TreeCommand enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 157
diff changeset
26 private Thread acceptThread;
157
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
27 protected final static String versionMsg_3_856 = "RFB 003.856\n";
223
3189e210a7ed indent fix.
oc
parents: 215
diff changeset
28
207
b31903e5b02d rename myRFBProto
oc
parents: 204
diff changeset
29 public TreeVncCommandChannelListener(TreeRFBProto _rfb, int p) {
157
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
30 rfb = _rfb;
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
31 port = p;
159
1c9f6acdfeb2 TreeCommand enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 157
diff changeset
32
157
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
33 }
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
34
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
35 public void commandMainLoop() {
223
3189e210a7ed indent fix.
oc
parents: 215
diff changeset
36 acceptThread = new Thread(new Runnable() {
3189e210a7ed indent fix.
oc
parents: 215
diff changeset
37 @Override
3189e210a7ed indent fix.
oc
parents: 215
diff changeset
38 public void run() {
3189e210a7ed indent fix.
oc
parents: 215
diff changeset
39 TreeVncCommand cmd = null;
3189e210a7ed indent fix.
oc
parents: 215
diff changeset
40 do {
3189e210a7ed indent fix.
oc
parents: 215
diff changeset
41 try {
3189e210a7ed indent fix.
oc
parents: 215
diff changeset
42 cmd = cmdQueue.poll(1000, TimeUnit.MILLISECONDS);
3189e210a7ed indent fix.
oc
parents: 215
diff changeset
43 } catch (InterruptedException e) {
3189e210a7ed indent fix.
oc
parents: 215
diff changeset
44 continue;
3189e210a7ed indent fix.
oc
parents: 215
diff changeset
45 }
3189e210a7ed indent fix.
oc
parents: 215
diff changeset
46 if (cmd!=null) {
3189e210a7ed indent fix.
oc
parents: 215
diff changeset
47 cmd.handleTreeVncCommand();
3189e210a7ed indent fix.
oc
parents: 215
diff changeset
48 }
3189e210a7ed indent fix.
oc
parents: 215
diff changeset
49 } while (cmd == null || cmd.getCommand() != TreeCommand.QUIT_LOOP);
3189e210a7ed indent fix.
oc
parents: 215
diff changeset
50 }
3189e210a7ed indent fix.
oc
parents: 215
diff changeset
51 },"root-command-loop");
3189e210a7ed indent fix.
oc
parents: 215
diff changeset
52 acceptThread.start();
157
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
53 }
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
54
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
55 public void run() {
159
1c9f6acdfeb2 TreeCommand enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 157
diff changeset
56 commandMainLoop();
157
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
57 while (true) {
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
58 try {
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
59 final Socket newCli = rfb.accept();
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
60 final OutputStream os = newCli.getOutputStream();
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
61 final InputStream is = newCli.getInputStream();
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
62 new Thread(new Runnable() {
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
63 public void run() {
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
64 TreeVncCommand cmd = newClientHandler(newCli,new Writer(os), new Reader(is));
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
65 if (cmd!=null) cmdQueue.add(cmd);
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
66 }
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
67 },"accepting").start();
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
68 } catch (Exception e) {
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
69 System.out.println("failed to connect incoming client" + e.getMessage());
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
70 }
11
57ae9fbb1245 add files
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 }
157
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
72 }
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
73
231
0e0e6744432c get new nodeList for checkDelay.
oc
parents: 223
diff changeset
74
157
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
75 public TreeVncCommand newClientHandler (final Socket newCli, final Writer os, final Reader is) {
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
76 TreeVncCommand cmd = null;
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
77 try {
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
78 cmd = initialConnection(rfb, os, is, newCli);
161
e997deb54314 is os isn't closed in NEW_NODE command.
oc
parents: 160
diff changeset
79 if (cmd!=null && cmd.getCommand()!=TreeCommand.NEW_NODE) {
157
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
80 // TreeVNC command is processed
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
81 newCli.close();
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
82 return cmd;
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
83 }
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
84 } catch (Exception e) {
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
85 try {
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
86 System.out.println("new client faild :" + e.getMessage());
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
87 newCli.close();
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
88 return null;
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
89 } catch (IOException e1) {
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
90 System.out.println("new client close faild");
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
91 return null;
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
92 }
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
93 }
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
94 return cmd;
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
95 }
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
96
207
b31903e5b02d rename myRFBProto
oc
parents: 204
diff changeset
97 public TreeVncCommand initialConnection(TreeRFBProto myRfbProto, final Writer os, final Reader is, Socket connection)
157
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
98 throws IOException, TransportException {
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
99 /**
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
100 * initial connection of RFB protocol
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
101 */
204
d9d234715853 TreeManager for each interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 169
diff changeset
102 InetAddress adr = connection.getLocalAddress();
d9d234715853 TreeManager for each interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 169
diff changeset
103 String myHostAddress =adr .getHostAddress();
d9d234715853 TreeManager for each interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 169
diff changeset
104 String intf = NetworkInterface.getByInetAddress(adr).getName();
157
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
105 sendRfbVersion(os);
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
106 byte[] b;
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
107 if ((b = readVersionMsg(is, os))!=null) {
204
d9d234715853 TreeManager for each interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 169
diff changeset
108 TreeVncCommand cmd = treeVncCommand(b,is,os,myHostAddress,intf);
157
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
109 if (cmd!=null) return cmd;
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
110 }
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
111 sendSecurityType(os);
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
112 readSecType(is);
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
113 sendSecResult(os);
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
114 readClientInit(is);
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
115 sendInitData(os);
159
1c9f6acdfeb2 TreeCommand enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 157
diff changeset
116 return new TreeVncCommand(rfb, myHostAddress, TreeCommand.NEW_NODE, os,is,connection);
157
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
117 }
11
57ae9fbb1245 add files
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
118
157
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
119 /**
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
120 * handle TreeVNC Command
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
121 * @param b byte [] command
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
122 * @param is
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
123 * @param os
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
124 * @param myHostName
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
125 * @return
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
126 * @throws TransportException
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
127 * @throws IOException
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
128 *
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
129 * TreeVNC Command is sent as a possible replied version message. 12 bytes is already read.
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
130 * Command 4 byte (including padding)
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
131 * lenght 4 byte
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
132 * port 4 byte
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
133 * rest of data ( add padding if it is shorter than 12 byte)
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
134 */
204
d9d234715853 TreeManager for each interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 169
diff changeset
135 TreeVncCommand treeVncCommand(byte[] b, Reader is, Writer os, String myHostName,String intf) throws TransportException, IOException {
157
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
136 ByteBuffer buf = ByteBuffer.wrap(b);
159
1c9f6acdfeb2 TreeCommand enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 157
diff changeset
137 TreeCommand command = TreeCommand.create(buf.get()&0xff); // make it unsigned
169
8ab1f6905db4 Try to hide root frame
oc
parents: 164
diff changeset
138 buf.get();
8ab1f6905db4 Try to hide root frame
oc
parents: 164
diff changeset
139 short value = buf.getShort();
157
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
140 int length = buf.getInt();
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
141 int port = buf.getInt();
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
142 String hostname = null;
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
143 if (length>4) {
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
144 if (length>1024) {
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
145 System.out.println("Too long TreeVncCommand ");
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
146 return null;
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
147 }
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
148 byte namebuf[] = new byte[length-4];
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
149 try {
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
150 is.readBytes(namebuf);
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
151 } catch (TransportException e) {
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
152 return null;
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
153 }
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
154 hostname = new String(namebuf);
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
155 }
204
d9d234715853 TreeManager for each interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 169
diff changeset
156 return new TreeVncCommand(rfb, myHostName, command, port, hostname, intf, value);
157
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
157 }
223
3189e210a7ed indent fix.
oc
parents: 215
diff changeset
158
157
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
159
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
160 void sendRfbVersion(Writer writer) throws IOException, TransportException {
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
161 writer.write(versionMsg_3_856.getBytes());
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
162 }
223
3189e210a7ed indent fix.
oc
parents: 215
diff changeset
163
157
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
164 byte[] readVersionMsg(Reader reader, Writer writer) throws IOException, TransportException {
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
165
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
166 byte[] b = new byte[HandshakeState.PROTOCOL_STRING_LENGTH ];
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
167
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
168 reader.readBytes(b);
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
169
159
1c9f6acdfeb2 TreeCommand enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 157
diff changeset
170 if ((b[0]&0xff)>=220) return b; // TreeVNC extension command.
157
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
171 if ((b[0] != 'R') || (b[1] != 'F') || (b[2] != 'B') || (b[3] != ' ')
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
172 || (b[4] < '0') || (b[4] > '9') || (b[5] < '0') || (b[5] > '9')
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
173 || (b[6] < '0') || (b[6] > '9') || (b[7] != '.')
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
174 || (b[8] < '0') || (b[8] > '9') || (b[9] < '0') || (b[9] > '9')
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
175 || (b[10] < '0') || (b[10] > '9') || (b[11] != '\n')) {
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
176 throw new IOException("this is not an RFB server");
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
177 }
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
178
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
179 int rfbMajor = (b[4] - '0') * 100 + (b[5] - '0') * 10 + (b[6] - '0');
223
3189e210a7ed indent fix.
oc
parents: 215
diff changeset
180 // int rfbMinor = (b[8] - '0') * 100 + (b[9] - '0') * 10 + (b[10] - '0');
157
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
181
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
182 if (rfbMajor < 3) {
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
183 throw new IOException(
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
184 "RFB server does not support protocol version 3");
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
185 }
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
186
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
187 return null;
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
188 }
223
3189e210a7ed indent fix.
oc
parents: 215
diff changeset
189
3189e210a7ed indent fix.
oc
parents: 215
diff changeset
190
157
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
191 void readSecType(Reader reader) throws TransportException {
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
192 byte[] b = new byte[1];
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
193 reader.read(b);
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
194 }
223
3189e210a7ed indent fix.
oc
parents: 215
diff changeset
195
157
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
196 void sendSecurityType(Writer os) throws TransportException {
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
197 // number-of-security-types
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
198 os.writeInt(1);
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
199 // security-types
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
200 // 1:None
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
201 os.writeInt(1);
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
202
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
203 /*
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
204 * os.write(4); os.write(30); os.write(31); os.write(32); os.write(35);
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
205 * os.flush();
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
206 */
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
207 }
223
3189e210a7ed indent fix.
oc
parents: 215
diff changeset
208
157
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
209 void sendSecResult(Writer os) throws TransportException {
223
3189e210a7ed indent fix.
oc
parents: 215
diff changeset
210 ByteBuffer b = ByteBuffer.allocate(4);
3189e210a7ed indent fix.
oc
parents: 215
diff changeset
211 b.order(ByteOrder.BIG_ENDIAN);
3189e210a7ed indent fix.
oc
parents: 215
diff changeset
212 b.putInt(0);
3189e210a7ed indent fix.
oc
parents: 215
diff changeset
213 os.write(b.array());
157
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
214 }
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
215
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
216 void readClientInit(Reader in) throws TransportException {
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
217 byte[] b = new byte[0];
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
218 in.readBytes(b);
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
219 }
223
3189e210a7ed indent fix.
oc
parents: 215
diff changeset
220
164
86289e56263c Send initData in server change
oc
parents: 161
diff changeset
221 byte initData[] = {7, -128, 4, 56, 32, 24, 0, 1, 0, -1, 0, -1, 0, -1, 16, 8, 0, 0, 0, 0, 0, 0, 0, 7, 103, 105, 114, 101, 102, 108, 121};
157
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
222 void sendInitData(Writer os) throws TransportException {
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
223 // In case of "-d" we have no context
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
224 ProtocolContext context = rfb.context;
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
225 if (context != null){
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
226 os.write(context.getInitData());
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
227 } else {
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
228 // Send dummy data
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
229 os.write(initData);
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
230 }
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
231 }
159
1c9f6acdfeb2 TreeCommand enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 157
diff changeset
232
1c9f6acdfeb2 TreeCommand enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 157
diff changeset
233 public void waitForShutdown() {
1c9f6acdfeb2 TreeCommand enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 157
diff changeset
234 if (acceptThread!=null)
1c9f6acdfeb2 TreeCommand enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 157
diff changeset
235 try {
1c9f6acdfeb2 TreeCommand enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 157
diff changeset
236 acceptThread.join();
1c9f6acdfeb2 TreeCommand enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 157
diff changeset
237 } catch (InterruptedException e) {
1c9f6acdfeb2 TreeCommand enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 157
diff changeset
238 }
1c9f6acdfeb2 TreeCommand enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 157
diff changeset
239 }
11
57ae9fbb1245 add files
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
240 }