Mercurial > hg > Applications > TreeVNC
changeset 155:1c95bd5bebcf
root finder for multiple network.
author | oc |
---|---|
date | Fri, 13 Jun 2014 18:51:14 +0900 |
parents | c3158d9e2c0b |
children | 93d903877c6b |
files | src/main/java/jp/ac/u_ryukyu/treevnc/client/TreeVncProtocol.java src/main/java/jp/ac/u_ryukyu/treevnc/server/TreeRootFinderListener.java |
diffstat | 2 files changed, 10 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/client/TreeVncProtocol.java Fri Jun 13 18:16:27 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/client/TreeVncProtocol.java Fri Jun 13 18:51:14 2014 +0900 @@ -45,8 +45,8 @@ } - public void findRootReply(String hostname, int port) throws IOException { - sendWithHostAndPort(ProtocolContext.FIND_ROOT_REPLY, hostname, port); + public void findRootReply(int port) throws IOException { + sendWithHostAndPort(ProtocolContext.FIND_ROOT_REPLY, null, port); } public void whereToConnect(String hostname, int port) throws IOException { @@ -65,6 +65,11 @@ public void sendWithHostAndPort(int command, String hostname, int port) throws IOException { openport(); + if (hostname == null) { + // in case of root finder, we can't get localaddress from datagram packet. + // so use local part of TCP socket. + hostname = echoSocket.getLocalAddress().getHostAddress(); + } int cmdlen = 4+4+4+hostname.length(); if (cmdlen < 12) cmdlen=12; ByteBuffer buf = ByteBuffer.allocate(cmdlen);
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/server/TreeRootFinderListener.java Fri Jun 13 18:16:27 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/server/TreeRootFinderListener.java Fri Jun 13 18:51:14 2014 +0900 @@ -35,6 +35,7 @@ soc.joinGroup(mAddr); while (!stopFlag) { soc.receive(recvPacket); + String hostname = recvPacket.getAddress().getHostAddress(); byte[] reply = recvPacket.getData(); int len = recvPacket.getLength(); if (len != 12) { @@ -49,9 +50,9 @@ port = port * 256 + reply[10]; port = port * 256 + reply[11]; - TreeVncProtocol t = new TreeVncProtocol("", port); + TreeVncProtocol t = new TreeVncProtocol(hostname, port); try { - t.findRootReply(getMyAddress(), vps.getRfb().getAcceptPort()); + t.findRootReply(vps.getRfb().getAcceptPort()); } catch (IOException e) { e.printStackTrace(); }