Mercurial > hg > Applications > TreeVNC
annotate src/main/java/jp/ac/u_ryukyu/treevnc/FindRoot.java @ 514:887ebd993b3d
separate rfb broadcast
author | mir3636 |
---|---|
date | Thu, 21 Feb 2019 16:52:21 +0900 |
parents | b97fdcd337fe |
children | 7071b01621c2 |
rev | line source |
---|---|
206 | 1 package jp.ac.u_ryukyu.treevnc; |
1 | 2 |
434
aad75cd6d9e2
Multicast joins both ipv4 and ipv6 now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
398
diff
changeset
|
3 import com.glavsoft.rfb.protocol.ProtocolContext.TreeCommand; |
aad75cd6d9e2
Multicast joins both ipv4 and ipv6 now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
398
diff
changeset
|
4 import com.glavsoft.viewer.swing.ConnectionParams; |
aad75cd6d9e2
Multicast joins both ipv4 and ipv6 now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
398
diff
changeset
|
5 |
82 | 6 import java.io.BufferedReader; |
1 | 7 import java.io.IOException; |
436
9db8862ef200
remove unsed code in FindRoot
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
434
diff
changeset
|
8 import java.net.DatagramPacket; |
9db8862ef200
remove unsed code in FindRoot
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
434
diff
changeset
|
9 import java.net.InetAddress; |
9db8862ef200
remove unsed code in FindRoot
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
434
diff
changeset
|
10 import java.net.MulticastSocket; |
9db8862ef200
remove unsed code in FindRoot
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
434
diff
changeset
|
11 import java.net.ServerSocket; |
125 | 12 import java.nio.ByteBuffer; |
13 import java.nio.ByteOrder; | |
206 | 14 |
436
9db8862ef200
remove unsed code in FindRoot
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
434
diff
changeset
|
15 public class FindRoot { |
1 | 16 final int BUFSIZE = 1024; |
17 private MulticastSocket soc; | |
434
aad75cd6d9e2
Multicast joins both ipv4 and ipv6 now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
398
diff
changeset
|
18 private InetAddress mAddr; |
82 | 19 private ServerSocket server = null; |
20 private BufferedReader is; | |
126 | 21 private int port; |
327
293c35aa902b
add error message, add assure stream close, delete firstTime value in TreeRFBProto.
oc
parents:
288
diff
changeset
|
22 private boolean stopFlag = false; |
82 | 23 private String proxyAddr; |
24 | |
125 | 25 /** |
287 | 26 * To find vnc root, a client sends a multicast packet. |
436
9db8862ef200
remove unsed code in FindRoot
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
434
diff
changeset
|
27 * @param _port TreeVNC waiting port |
9db8862ef200
remove unsed code in FindRoot
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
434
diff
changeset
|
28 * @param createConnectionParam no use now |
125 | 29 */ |
134
128cce60c43c
where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
131
diff
changeset
|
30 public FindRoot(int _port, CreateConnectionParam createConnectionParam) { |
434
aad75cd6d9e2
Multicast joins both ipv4 and ipv6 now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
398
diff
changeset
|
31 port = _port; |
aad75cd6d9e2
Multicast joins both ipv4 and ipv6 now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
398
diff
changeset
|
32 try { |
aad75cd6d9e2
Multicast joins both ipv4 and ipv6 now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
398
diff
changeset
|
33 soc = TreeRootFinderListener.createMulticastSocket(); |
aad75cd6d9e2
Multicast joins both ipv4 and ipv6 now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
398
diff
changeset
|
34 mAddr = InetAddress.getByName(TreeRootFinderListener.McastAddr); |
aad75cd6d9e2
Multicast joins both ipv4 and ipv6 now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
398
diff
changeset
|
35 System.out.println("FindRoot socket on " + TreeRootFinderListener.McastAddr + " " + mAddr + " port " + _port); |
aad75cd6d9e2
Multicast joins both ipv4 and ipv6 now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
398
diff
changeset
|
36 } catch (IOException e) { |
aad75cd6d9e2
Multicast joins both ipv4 and ipv6 now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
398
diff
changeset
|
37 System.out.println("cannot create FindRoot socket. " + e); |
aad75cd6d9e2
Multicast joins both ipv4 and ipv6 now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
398
diff
changeset
|
38 } |
aad75cd6d9e2
Multicast joins both ipv4 and ipv6 now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
398
diff
changeset
|
39 } |
82 | 40 |
130 | 41 /** |
42 * send find root message. | |
43 * | |
44 */ | |
125 | 45 public void findRoot() { |
46 ByteBuffer buf = ByteBuffer.allocate(12); | |
47 buf.order(ByteOrder.BIG_ENDIAN); | |
159 | 48 buf.put((byte) TreeCommand.FIND_ROOT.cmd); |
125 | 49 buf.put((byte) 0); |
50 buf.put((byte) 0); | |
51 buf.put((byte) 0); | |
52 buf.putInt(4); // length | |
53 buf.putInt(port); | |
54 buf.flip(); | |
55 | |
437 | 56 |
125 | 57 try { |
437 | 58 DatagramPacket sendPacket = new DatagramPacket(buf.array(), buf.limit(), InetAddress.getByName(TreeRootFinderListener.Ipv6McastAddr), ConnectionParams.DEFAULT_VNC_ROOT_FINDER); |
59 soc.send(sendPacket); | |
125 | 60 } catch (IOException e) { |
327
293c35aa902b
add error message, add assure stream close, delete firstTime value in TreeRFBProto.
oc
parents:
288
diff
changeset
|
61 System.out.println("cannot send FindRoot packet."); |
125 | 62 e.printStackTrace(); |
63 } | |
437 | 64 |
65 try { | |
66 DatagramPacket sendPacket1 = new DatagramPacket(buf.array(), buf.limit(), InetAddress.getByName(TreeRootFinderListener.Ipv4McastAddr), ConnectionParams.DEFAULT_VNC_ROOT_FINDER); | |
67 soc.send(sendPacket1); | |
68 } catch (IOException e) { | |
69 System.out.println("cannot send FindRoot packet."); | |
70 e.printStackTrace(); | |
71 } | |
436
9db8862ef200
remove unsed code in FindRoot
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
434
diff
changeset
|
72 soc.close(); |
125 | 73 } |
436
9db8862ef200
remove unsed code in FindRoot
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
434
diff
changeset
|
74 |
82 | 75 |
76 | |
1 | 77 } |