Mercurial > hg > Members > riono > TreeVNC_ja_comment
comparison src/main/java/jp/ac/u_ryukyu/treevnc/TreeRootFinderListener.java @ 505:af958194248b
change replyToRootSearchMulticast
author | oshiro |
---|---|
date | Mon, 18 Feb 2019 18:46:23 +0900 |
parents | 432e2967eaab |
children | 3fe7e1a372df |
comparison
equal
deleted
inserted
replaced
504:d409e89ec8ec | 505:af958194248b |
---|---|
1 package jp.ac.u_ryukyu.treevnc; | 1 package jp.ac.u_ryukyu.treevnc; |
2 | 2 |
3 import com.glavsoft.rfb.protocol.ProtocolContext.TreeCommand; | 3 import com.glavsoft.rfb.protocol.ProtocolContext.TreeCommand; |
4 import com.glavsoft.rfb.protocol.ReceiverTask; | |
5 import com.glavsoft.transport.Reader; | |
4 import com.glavsoft.viewer.ViewerInterface; | 6 import com.glavsoft.viewer.ViewerInterface; |
5 import com.glavsoft.viewer.swing.ConnectionParams; | 7 import com.glavsoft.viewer.swing.ConnectionParams; |
6 | 8 |
9 import java.io.ByteArrayInputStream; | |
7 import java.io.IOException; | 10 import java.io.IOException; |
8 import java.net.*; | 11 import java.net.*; |
12 | |
13 import static com.glavsoft.rfb.protocol.ReceiverTask.FRAMEBUFFER_UPDATE; | |
9 | 14 |
10 public class TreeRootFinderListener implements Runnable { | 15 public class TreeRootFinderListener implements Runnable { |
11 public static final String Ipv4McastAddr = "224.0.0.1"; | 16 public static final String Ipv4McastAddr = "224.0.0.1"; |
12 public static final String Ipv6McastAddr = "ff02::1"; | 17 public static final String Ipv6McastAddr = "ff02::1"; |
13 public static String McastAddr = Ipv4McastAddr; | 18 public static String McastAddr = Ipv4McastAddr; |
14 | 19 |
15 static final int BufSize = 1024; | 20 static final int BufSize = 1024; |
21 private ReceiverTask receiverTask; | |
16 private boolean stopFlag = false; | 22 private boolean stopFlag = false; |
17 private ViewerInterface vps; | 23 private ViewerInterface vps; |
18 private MulticastSocket soc; | 24 private MulticastSocket soc; |
19 private SecurityManager securityManager; | 25 private SecurityManager securityManager; |
20 | 26 |
21 public TreeRootFinderListener(ViewerInterface vncProxyService) { | 27 public TreeRootFinderListener(ViewerInterface vncProxyService) { |
22 vps = vncProxyService; | 28 vps = vncProxyService; |
29 } | |
30 | |
31 public TreeRootFinderListener(ViewerInterface vncProxyService, ReceiverTask receiverTask) { | |
32 vps = vncProxyService; | |
33 this.receiverTask = receiverTask; | |
23 } | 34 } |
24 | 35 |
25 public static MulticastSocket createMulticastSocket() throws IOException { | 36 public static MulticastSocket createMulticastSocket() throws IOException { |
26 MulticastSocket soc = new MulticastSocket(ConnectionParams.DEFAULT_VNC_ROOT_FINDER); | 37 MulticastSocket soc = new MulticastSocket(ConnectionParams.DEFAULT_VNC_ROOT_FINDER); |
27 try { | 38 try { |
51 while (!stopFlag) { | 62 while (!stopFlag) { |
52 soc.receive(recvPacket); | 63 soc.receive(recvPacket); |
53 String hostname = recvPacket.getAddress().getHostAddress(); | 64 String hostname = recvPacket.getAddress().getHostAddress(); |
54 byte[] reply = recvPacket.getData(); | 65 byte[] reply = recvPacket.getData(); |
55 int len = recvPacket.getLength(); | 66 int len = recvPacket.getLength(); |
56 if (len != 12) { | 67 if (len == 12 && (reply[0] & 0xff) == TreeCommand.FIND_ROOT.cmd) { |
57 continue; | 68 int port = reply[8]; |
69 port = port * 256 + reply[9]; | |
70 port = port * 256 + reply[10]; | |
71 port = port * 256 + reply[11]; | |
72 | |
73 TreeVncProtocol t = new TreeVncProtocol(hostname, port); | |
74 t.findRootReply(vps.getRfb().getAcceptPort()); | |
75 } else { | |
76 if (receiverTask != null) { | |
77 receiverTask.setReader(new Reader(new ByteArrayInputStream(reply))); | |
78 if (receiverTask.getMessageId() == FRAMEBUFFER_UPDATE) { | |
79 receiverTask.framebufferUpdateMessage(); | |
80 } | |
81 } | |
58 } | 82 } |
59 if ((reply[0]&0xff) != TreeCommand.FIND_ROOT.cmd) { | |
60 continue; | |
61 } | |
62 int port = reply[8]; | |
63 port = port * 256 + reply[9]; | |
64 port = port * 256 + reply[10]; | |
65 port = port * 256 + reply[11]; | |
66 | |
67 TreeVncProtocol t = new TreeVncProtocol(hostname, port); | |
68 t.findRootReply(vps.getRfb().getAcceptPort()); | |
69 if(stopFlag) break; | |
70 } | 83 } |
71 } catch (Exception e) { | 84 } catch (Exception e) { |
72 System.out.println("tree-root-find-listener :" + e.getMessage()); | 85 System.out.println("tree-root-find-listener :" + e.getMessage()); |
73 } | 86 } |
74 } | 87 } |