Mercurial > hg > Applications > TreeVNC
view 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 |
line wrap: on
line source
package jp.ac.u_ryukyu.treevnc; import com.glavsoft.rfb.protocol.ProtocolContext.TreeCommand; import com.glavsoft.viewer.swing.ConnectionParams; import java.io.BufferedReader; import java.io.IOException; import java.net.DatagramPacket; import java.net.InetAddress; import java.net.MulticastSocket; import java.net.ServerSocket; import java.nio.ByteBuffer; import java.nio.ByteOrder; public class FindRoot { final int BUFSIZE = 1024; private MulticastSocket soc; private InetAddress mAddr; private ServerSocket server = null; private BufferedReader is; private int port; private boolean stopFlag = false; private String proxyAddr; /** * To find vnc root, a client sends a multicast packet. * @param _port TreeVNC waiting port * @param createConnectionParam no use now */ public FindRoot(int _port, CreateConnectionParam createConnectionParam) { port = _port; try { soc = TreeRootFinderListener.createMulticastSocket(); mAddr = InetAddress.getByName(TreeRootFinderListener.McastAddr); System.out.println("FindRoot socket on " + TreeRootFinderListener.McastAddr + " " + mAddr + " port " + _port); } catch (IOException e) { System.out.println("cannot create FindRoot socket. " + e); } } /** * send find root message. * */ public void findRoot() { ByteBuffer buf = ByteBuffer.allocate(12); buf.order(ByteOrder.BIG_ENDIAN); buf.put((byte) TreeCommand.FIND_ROOT.cmd); buf.put((byte) 0); buf.put((byte) 0); buf.put((byte) 0); buf.putInt(4); // length buf.putInt(port); buf.flip(); try { DatagramPacket sendPacket = new DatagramPacket(buf.array(), buf.limit(), InetAddress.getByName(TreeRootFinderListener.Ipv6McastAddr), ConnectionParams.DEFAULT_VNC_ROOT_FINDER); soc.send(sendPacket); } catch (IOException e) { System.out.println("cannot send FindRoot packet."); e.printStackTrace(); } try { DatagramPacket sendPacket1 = new DatagramPacket(buf.array(), buf.limit(), InetAddress.getByName(TreeRootFinderListener.Ipv4McastAddr), ConnectionParams.DEFAULT_VNC_ROOT_FINDER); soc.send(sendPacket1); } catch (IOException e) { System.out.println("cannot send FindRoot packet."); e.printStackTrace(); } soc.close(); } }