Mercurial > hg > Members > riono > TreeVNC_ja_comment
comparison src/main/java/jp/ac/u_ryukyu/treevnc/TreeVncCommandChannelListener.java @ 204:d9d234715853
TreeManager for each interface
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 27 Jun 2014 21:37:20 +0900 |
parents | 8ab1f6905db4 |
children | b31903e5b02d |
comparison
equal
deleted
inserted
replaced
203:2f6237fea67e | 204:d9d234715853 |
---|---|
1 package jp.ac.u_ryukyu.treevnc; | 1 package jp.ac.u_ryukyu.treevnc; |
2 import java.net.InetAddress; | |
3 import java.net.NetworkInterface; | |
2 import java.net.Socket; | 4 import java.net.Socket; |
3 import java.nio.ByteBuffer; | 5 import java.nio.ByteBuffer; |
4 import java.nio.ByteOrder; | 6 import java.nio.ByteOrder; |
5 import java.util.concurrent.LinkedBlockingQueue; | 7 import java.util.concurrent.LinkedBlockingQueue; |
6 import java.util.concurrent.TimeUnit; | 8 import java.util.concurrent.TimeUnit; |
93 public TreeVncCommand initialConnection(MyRfbProto myRfbProto, final Writer os, final Reader is, Socket connection) | 95 public TreeVncCommand initialConnection(MyRfbProto myRfbProto, final Writer os, final Reader is, Socket connection) |
94 throws IOException, TransportException { | 96 throws IOException, TransportException { |
95 /** | 97 /** |
96 * initial connection of RFB protocol | 98 * initial connection of RFB protocol |
97 */ | 99 */ |
98 String myHostAddress = connection.getLocalAddress().getHostAddress(); | 100 InetAddress adr = connection.getLocalAddress(); |
101 String myHostAddress =adr .getHostAddress(); | |
102 String intf = NetworkInterface.getByInetAddress(adr).getName(); | |
99 sendRfbVersion(os); | 103 sendRfbVersion(os); |
100 byte[] b; | 104 byte[] b; |
101 if ((b = readVersionMsg(is, os))!=null) { | 105 if ((b = readVersionMsg(is, os))!=null) { |
102 TreeVncCommand cmd = treeVncCommand(b,is,os,myHostAddress); | 106 TreeVncCommand cmd = treeVncCommand(b,is,os,myHostAddress,intf); |
103 if (cmd!=null) return cmd; | 107 if (cmd!=null) return cmd; |
104 } | 108 } |
105 sendSecurityType(os); | 109 sendSecurityType(os); |
106 readSecType(is); | 110 readSecType(is); |
107 sendSecResult(os); | 111 sendSecResult(os); |
124 * Command 4 byte (including padding) | 128 * Command 4 byte (including padding) |
125 * lenght 4 byte | 129 * lenght 4 byte |
126 * port 4 byte | 130 * port 4 byte |
127 * rest of data ( add padding if it is shorter than 12 byte) | 131 * rest of data ( add padding if it is shorter than 12 byte) |
128 */ | 132 */ |
129 TreeVncCommand treeVncCommand(byte[] b, Reader is, Writer os, String myHostName) throws TransportException, IOException { | 133 TreeVncCommand treeVncCommand(byte[] b, Reader is, Writer os, String myHostName,String intf) throws TransportException, IOException { |
130 ByteBuffer buf = ByteBuffer.wrap(b); | 134 ByteBuffer buf = ByteBuffer.wrap(b); |
131 TreeCommand command = TreeCommand.create(buf.get()&0xff); // make it unsigned | 135 TreeCommand command = TreeCommand.create(buf.get()&0xff); // make it unsigned |
132 buf.get(); | 136 buf.get(); |
133 short value = buf.getShort(); | 137 short value = buf.getShort(); |
134 int length = buf.getInt(); | 138 int length = buf.getInt(); |
145 } catch (TransportException e) { | 149 } catch (TransportException e) { |
146 return null; | 150 return null; |
147 } | 151 } |
148 hostname = new String(namebuf); | 152 hostname = new String(namebuf); |
149 } | 153 } |
150 return new TreeVncCommand(rfb, myHostName, command, port, hostname, value); | 154 return new TreeVncCommand(rfb, myHostName, command, port, hostname, intf, value); |
151 } | 155 } |
152 | 156 |
153 | 157 |
154 void sendRfbVersion(Writer writer) throws IOException, TransportException { | 158 void sendRfbVersion(Writer writer) throws IOException, TransportException { |
155 writer.write(versionMsg_3_856.getBytes()); | 159 writer.write(versionMsg_3_856.getBytes()); |