annotate src/main/java/jp/ac/u_ryukyu/treevnc/CreateConnectionParam.java @ 145:649794dfb9d5

add my hostname to handle multiple network
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 12 Jun 2014 22:01:05 +0900
parents 1e004d9c599d
children 1291cf1122ca
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
67
2908e4b95b0a add file
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 package jp.ac.u_ryukyu.treevnc;
2908e4b95b0a add file
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2
134
128cce60c43c where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 130
diff changeset
3 import java.io.IOException;
128cce60c43c where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 130
diff changeset
4
67
2908e4b95b0a add file
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 import com.glavsoft.viewer.ViewerImpl;
130
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 128
diff changeset
6 import com.glavsoft.viewer.swing.ConnectionParams;
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 128
diff changeset
7
134
128cce60c43c where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 130
diff changeset
8 import jp.ac.u_ryukyu.treevnc.client.FindRoot;
125
32c6563492f3 add vnc protocol command sender.
oc
parents: 87
diff changeset
9 import jp.ac.u_ryukyu.treevnc.client.TreeVncProtocol;
81
f93d0286c2ab root find multicast send port number now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 80
diff changeset
10
67
2908e4b95b0a add file
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 public class CreateConnectionParam {
2908e4b95b0a add file
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 private String hostName;
130
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 128
diff changeset
13 private int portNumber = ConnectionParams.DEFAULT_VNC_ROOT;
67
2908e4b95b0a add file
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 private MyRfbProto rfb;
145
649794dfb9d5 add my hostname to handle multiple network
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 144
diff changeset
15 private String myHostName;
81
f93d0286c2ab root find multicast send port number now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 80
diff changeset
16
67
2908e4b95b0a add file
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 public CreateConnectionParam(MyRfbProto rfb) {
2908e4b95b0a add file
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 this.rfb = rfb;
2908e4b95b0a add file
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 }
2908e4b95b0a add file
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
142
d2af9edb1803 fix selectRfbSelectPort.
oc
parents: 141
diff changeset
21 public synchronized void findTreeVncRoot() throws InterruptedException {
144
1e004d9c599d notify connection panel
oc
parents: 143
diff changeset
22 rfb.createRootSelectionPanel(this);
134
128cce60c43c where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 130
diff changeset
23 FindRoot getBcast = new FindRoot(rfb.acceptPort,this);
128cce60c43c where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 130
diff changeset
24 getBcast.findRoot();
130
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 128
diff changeset
25 // wait for RootSelection
141
1fa40e04f099 minor fix
oc
parents: 139
diff changeset
26 wait();
67
2908e4b95b0a add file
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 }
2908e4b95b0a add file
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28
134
128cce60c43c where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 130
diff changeset
29 /**
128cce60c43c where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 130
diff changeset
30 * To find parent, send WHERE_TO_CONNECT command to the TreeVNC root
128cce60c43c where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 130
diff changeset
31 * Incoming CONNECT_TO message is handled in MyRFBProto
128cce60c43c where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 130
diff changeset
32 * @param v
128cce60c43c where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 130
diff changeset
33 */
67
2908e4b95b0a add file
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 public void createConnectionParam(ViewerImpl v) {
134
128cce60c43c where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 130
diff changeset
35 TreeVncProtocol echo = new TreeVncProtocol(hostName,portNumber);
67
2908e4b95b0a add file
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 rfb.setEcho(echo);
134
128cce60c43c where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 130
diff changeset
37 try {
145
649794dfb9d5 add my hostname to handle multiple network
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 144
diff changeset
38 echo.whereToConnect(myHostName,rfb.getAcceptPort());
134
128cce60c43c where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 130
diff changeset
39 } catch (IOException e) {
128cce60c43c where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 130
diff changeset
40 // cannot send where to connect
128cce60c43c where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 130
diff changeset
41 }
67
2908e4b95b0a add file
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 }
130
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 128
diff changeset
43
128
0cf1541f69bb find root reply is accepted.
oc
parents: 127
diff changeset
44 public void runAcceptThread() {
142
d2af9edb1803 fix selectRfbSelectPort.
oc
parents: 141
diff changeset
45 rfb.selectPort(ConnectionParams.DEFAULT_VNC_ROOT);
d2af9edb1803 fix selectRfbSelectPort.
oc
parents: 141
diff changeset
46 AcceptThread acceptThread = new AcceptThread(rfb, rfb.getAcceptPort());
d2af9edb1803 fix selectRfbSelectPort.
oc
parents: 141
diff changeset
47 Thread accThread = new Thread(acceptThread);
67
2908e4b95b0a add file
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 accThread.start();
2908e4b95b0a add file
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 }
130
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 128
diff changeset
50
145
649794dfb9d5 add my hostname to handle multiple network
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 144
diff changeset
51 public synchronized void setHostName(String _hostName, int port, String _myHostName) {
130
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 128
diff changeset
52 hostName = _hostName;
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 128
diff changeset
53 portNumber = port;
145
649794dfb9d5 add my hostname to handle multiple network
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 144
diff changeset
54 myHostName = _myHostName;
144
1e004d9c599d notify connection panel
oc
parents: 143
diff changeset
55 notify();
130
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 128
diff changeset
56 }
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 128
diff changeset
57
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 128
diff changeset
58 public void setHostName(String hostAndPort) {
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 128
diff changeset
59 int i = hostAndPort.indexOf(':');
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 128
diff changeset
60 if (i>0) {
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 128
diff changeset
61 portNumber = Integer.parseInt(hostAndPort.substring(i+1));
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 128
diff changeset
62 hostName = hostAndPort.substring(0,i);
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 128
diff changeset
63 } else
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 128
diff changeset
64 hostName = hostAndPort;
67
2908e4b95b0a add file
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 }
2908e4b95b0a add file
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
66
145
649794dfb9d5 add my hostname to handle multiple network
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 144
diff changeset
67 public String getMyHostName() {
649794dfb9d5 add my hostname to handle multiple network
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 144
diff changeset
68 return myHostName;
649794dfb9d5 add my hostname to handle multiple network
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 144
diff changeset
69 }
67
2908e4b95b0a add file
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 }