comparison src/main/java/jp/ac/u_ryukyu/treevnc/CreateConnectionParam.java @ 130:1f6bfaa3281b

root selection panel
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 07 Jun 2014 00:03:13 +0900
parents 0cf1541f69bb
children 128cce60c43c
comparison
equal deleted inserted replaced
129:a6dc674546f2 130:1f6bfaa3281b
1 package jp.ac.u_ryukyu.treevnc; 1 package jp.ac.u_ryukyu.treevnc;
2 2
3 import java.util.logging.Logger;
4 import com.glavsoft.viewer.ViewerImpl; 3 import com.glavsoft.viewer.ViewerImpl;
4 import com.glavsoft.viewer.swing.ConnectionParams;
5
5 import jp.ac.u_ryukyu.treevnc.client.TreeVncProtocol; 6 import jp.ac.u_ryukyu.treevnc.client.TreeVncProtocol;
6 import jp.ac.u_ryukyu.treevnc.client.GetHostClient; 7 import jp.ac.u_ryukyu.treevnc.client.GetHostClient;
7 8
8
9
10 public class CreateConnectionParam { 9 public class CreateConnectionParam {
11 private String hostName; 10 private String hostName;
12 private int portNumber = 5999; 11 private int portNumber = ConnectionParams.DEFAULT_VNC_ROOT;
13 private MyRfbProto rfb; 12 private MyRfbProto rfb;
14 private final Logger logger;
15 13
16 public CreateConnectionParam(MyRfbProto rfb) { 14 public CreateConnectionParam(MyRfbProto rfb) {
17 this.rfb = rfb; 15 this.rfb = rfb;
18 logger = Logger.getLogger(getClass().getName());
19 } 16 }
20 17
21 public void findTreeVncRoot() { 18 public void findTreeVncRoot() throws InterruptedException {
22 GetHostClient getBcast = new GetHostClient(rfb.acceptPort); 19 GetHostClient getBcast = new GetHostClient(rfb.acceptPort,this);
23 getBcast.getHost(); 20 getBcast.getHost();
24 portNumber = 0; 21 // wait for RootSelection
25 do { 22 wait();
26 try {
27 Thread runBcast = new Thread(getBcast, "TreeVNC-root-finder");
28 runBcast.start();
29 hostName = getBcast.textAddress(); // wait for root reply to our broadcast
30 portNumber = Integer.parseInt(getBcast.textPort());
31 } catch (Exception e) {
32 logger.info("can't get parent address or port");
33 }
34 getBcast.interrupt();
35 } while ( portNumber == 0);
36
37 } 23 }
38 24
39 public void createConnectionParam(ViewerImpl v) { 25 public void createConnectionParam(ViewerImpl v) {
40 TreeVncProtocol echo = new TreeVncProtocol(hostName, 9999); 26 TreeVncProtocol echo = new TreeVncProtocol(hostName, 9999);
41 rfb.setEcho(echo); 27 rfb.setEcho(echo);
42 rfb.setProxyAddr(hostName); 28 rfb.setProxyAddr(hostName);
43 echo.getParentName(); 29 echo.getParentName();
44 v.setConnectionParam(echo.getParentsAddress(), portNumber); 30 v.setConnectionParam(echo.getParentsAddress(), portNumber);
45 } 31 }
46 32
47 public void runAcceptThread() { 33 public void runAcceptThread() {
48 Thread accThread = new Thread(new AcceptThread(rfb, portNumber)); 34 Thread accThread = new Thread(new AcceptThread(rfb, portNumber));
49 accThread.start(); 35 accThread.start();
50 } 36 }
51 37
52 public void setHostName(String _hostName) { 38 public void setHostName(String _hostName, int port) {
53 hostName = _hostName; 39 hostName = _hostName;
54 portNumber = 5999; 40 portNumber = port;
41 }
42
43 public void setHostName(String hostAndPort) {
44 int i = hostAndPort.indexOf(':');
45 if (i>0) {
46 portNumber = Integer.parseInt(hostAndPort.substring(i+1));
47 hostName = hostAndPort.substring(0,i);
48 } else
49 hostName = hostAndPort;
55 } 50 }
56 51
57 } 52 }