Mercurial > hg > Members > riono > TreeVNC_ja_comment
annotate src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java @ 111:a7988d3c0266
minor fix.
author | oc |
---|---|
date | Fri, 23 May 2014 20:24:43 +0900 |
parents | 457f9dfbf7ce |
children | 804b1ce07aa0 |
rev | line source |
---|---|
12 | 1 package jp.ac.u_ryukyu.treevnc.server; |
11 | 2 |
3 import java.awt.event.*; | |
4 import java.io.*; | |
38 | 5 import java.net.UnknownHostException; |
6 import java.util.LinkedList; | |
11 | 7 import java.util.logging.Logger; |
8 | |
31 | 9 import jp.ac.u_ryukyu.treevnc.AcceptThread; |
40 | 10 import jp.ac.u_ryukyu.treevnc.server.state.ChangeHost; |
31 | 11 |
59 | 12 import com.glavsoft.core.SettingsChangedEvent; |
11 | 13 import com.glavsoft.rfb.IChangeSettingsListener; |
14 import com.glavsoft.rfb.IRfbSessionListener; | |
15 import com.glavsoft.rfb.protocol.ProtocolSettings; | |
16 import com.glavsoft.viewer.Viewer; | |
17 import com.glavsoft.viewer.cli.Parser; | |
82 | 18 import com.glavsoft.viewer.swing.ConnectionParams; |
11 | 19 import com.glavsoft.viewer.swing.ParametersHandler; |
20 | |
45 | 21 public class VncProxyService extends Viewer implements Runnable, |
22 IRfbSessionListener, IChangeSettingsListener { | |
11 | 23 |
24 /** | |
25 * | |
26 */ | |
27 private static final long serialVersionUID = 1L; | |
28 | |
46 | 29 public static Logger logger = Logger.getLogger("com.glavsoft"); |
30 private boolean forceReconnection; | |
31 private String reconnectionReason; | |
32 private AcceptThread acceptThread; | |
33 private GetBroadCastProxy getCast; | |
92 | 34 private AcceptClient clients; |
40 | 35 public int opendPort; |
47 | 36 static VncProxyService currentVps; |
50
225e3873d75f
Modified to be able to specify the region of the screen in the argument.
one
parents:
49
diff
changeset
|
37 private int fbWidth = 0; |
69 | 38 private boolean firstTime = true; |
46 | 39 |
82 | 40 private int vncport = ConnectionParams.DEFAULT_RFB_PORT; |
41 | |
11 | 42 public VncProxyService() { |
77 | 43 ProtocolSettings.getDefaultSettings(); |
11 | 44 uiSettings = super.uiSettings; |
45 } | |
45 | 46 |
47 | 47 public VncProxyService(VncProxyService vps, String hostName) { |
48 this(); | |
49 connectionParams.hostName = hostName; | |
60 | 50 myRfb = vps.myRfb; |
47 | 51 forceReconnection = vps.forceReconnection; |
52 reconnectionReason = vps.reconnectionReason; | |
53 acceptThread = vps.acceptThread; | |
54 getCast = vps.getCast; | |
92 | 55 clients = vps.clients; |
47 | 56 opendPort = vps.opendPort; |
57 } | |
58 | |
11 | 59 public static void main(String[] argv) { |
60 String[] mainArgs = argv; | |
61 System.out.println(mainArgs.length); | |
62 // input into arguments Decision | |
60 | 63 |
11 | 64 Parser parser = new Parser(); |
65 ParametersHandler.completeParserOptions(parser); | |
66 | |
67 parser.parse(argv); | |
68 if (parser.isSet(ParametersHandler.ARG_HELP)) { | |
69 printUsage(parser.optionsUsage()); | |
70 System.exit(0); | |
71 } | |
46 | 72 VncProxyService vps = new VncProxyService(); |
61
d9cf08c6415c
During implementation change screen.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
60
diff
changeset
|
73 vps.initProxy1("localhost"); |
46 | 74 } |
75 | |
61
d9cf08c6415c
During implementation change screen.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
60
diff
changeset
|
76 private void initProxy1(String hostName) { |
60 | 77 myRfb = new MyRfbProtoProxy(); |
111 | 78 myRfb.setVncProxy(this); |
92 | 79 clients = new AcceptClient(); |
61
d9cf08c6415c
During implementation change screen.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
60
diff
changeset
|
80 isApplet = false; |
60 | 81 setIsTreeVNC(true); |
82 | 82 setConnectionParam(hostName,vncport); |
60 | 83 isApplet = true; |
84 run(); | |
46 | 85 createConnectionAndStart(); |
86 try { | |
87 threadSetAndStart(); | |
88 } catch (UnknownHostException e) { | |
60 | 89 |
46 | 90 } catch (IOException e) { |
91 | |
92 } | |
11 | 93 } |
97 | 94 |
106
01c0fd20c0b4
share screen enable cui flag.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
102
diff
changeset
|
95 /** |
01c0fd20c0b4
share screen enable cui flag.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
102
diff
changeset
|
96 * start new VNC server receiver with |
01c0fd20c0b4
share screen enable cui flag.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
102
diff
changeset
|
97 * inherited clients |
01c0fd20c0b4
share screen enable cui flag.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
102
diff
changeset
|
98 * @param vs |
01c0fd20c0b4
share screen enable cui flag.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
102
diff
changeset
|
99 * @param hostName |
01c0fd20c0b4
share screen enable cui flag.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
102
diff
changeset
|
100 */ |
97 | 101 private void inhelitClients(VncProxyService vs, String hostName) { |
102 myRfb.setReadyReconnect(false); | |
103 setConnectionParam(hostName,vncport); | |
104 isApplet = true; | |
105 this.setNoConnection(false); | |
106 run(); | |
107 firstTime = false; | |
108 createConnectionAndStart(); | |
109 } | |
45 | 110 |
38 | 111 public void createConnectionAndStart() { |
40 | 112 Thread thread; |
60 | 113 opendPort = myRfb.selectPort(5999); |
114 acceptThread = new AcceptThread(myRfb, opendPort); | |
88 | 115 thread = new Thread(acceptThread, "TreeVNC-accept"); |
38 | 116 thread.start(); |
69 | 117 if(firstTime) { |
118 getCast = new GetBroadCastProxy(this, | |
119 this.connectionParams.getHostName(), | |
120 this.connectionParams.getHostName()); | |
121 thread = new Thread(getCast); | |
122 thread.start(); | |
123 } | |
13 | 124 } |
11 | 125 |
60 | 126 public void proxyStart(String[] argv, int width, int height) { |
50
225e3873d75f
Modified to be able to specify the region of the screen in the argument.
one
parents:
49
diff
changeset
|
127 fbWidth = width; |
225e3873d75f
Modified to be able to specify the region of the screen in the argument.
one
parents:
49
diff
changeset
|
128 proxyStart(argv); |
225e3873d75f
Modified to be able to specify the region of the screen in the argument.
one
parents:
49
diff
changeset
|
129 } |
60 | 130 |
34 | 131 public void proxyStart(String[] argv) { |
132 // input into arguments Decision | |
133 Parser parser = new Parser(); | |
134 ParametersHandler.completeParserOptions(parser); | |
60 | 135 if (fbWidth == 0) |
50
225e3873d75f
Modified to be able to specify the region of the screen in the argument.
one
parents:
49
diff
changeset
|
136 parser.parse(argv); |
34 | 137 if (parser.isSet(ParametersHandler.ARG_HELP)) { |
138 printUsage(parser.optionsUsage()); | |
139 System.exit(0); | |
140 } | |
61
d9cf08c6415c
During implementation change screen.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
60
diff
changeset
|
141 initProxy1("localhost"); |
34 | 142 } |
143 | |
11 | 144 @Override |
145 public void destroy() { | |
146 | |
147 } | |
148 | |
149 @Override | |
150 public void windowClosing(WindowEvent e) { | |
151 if (e != null && e.getComponent() != null) { | |
152 e.getWindow().setVisible(false); | |
153 } | |
154 closeApp(); | |
155 } | |
45 | 156 |
38 | 157 private void threadSetAndStart() throws UnknownHostException, IOException { |
92 | 158 CreateThread createThread = new CreateThread(clients); |
38 | 159 Thread thread = new Thread(createThread); |
37 | 160 thread.start(); |
46 | 161 Thread thread2 = new Thread(new ChangeHost(this, forceReconnection)); |
162 thread2.start(); | |
37 | 163 } |
45 | 164 |
38 | 165 protected void socketClose() { |
166 } | |
45 | 167 |
38 | 168 @Override |
169 public void rfbSessionStopped(final String reason) { | |
59 | 170 |
38 | 171 } |
45 | 172 |
60 | 173 |
55 | 174 /** |
60 | 175 * chnageVNCServer is called when host change. |
176 * | |
177 * @param hostName | |
178 * HostAddress | |
179 * @param width | |
180 * FrameWidth | |
181 * @param height | |
182 * FrameHeight | |
94
75879c316796
synchronized wait for Rfb initialization in change server.
oc
parents:
93
diff
changeset
|
183 * @throws InterruptedException |
55 | 184 */ |
60 | 185 public void changeVNCServer(String hostName, int width, int height) |
94
75879c316796
synchronized wait for Rfb initialization in change server.
oc
parents:
93
diff
changeset
|
186 throws UnknownHostException, IOException, InterruptedException { |
102
1f7ee648e1f6
inflator in MyRfbProtoProxy should be renew to accept new VNC server socket.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
97
diff
changeset
|
187 // stop reader stop |
1f7ee648e1f6
inflator in MyRfbProtoProxy should be renew to accept new VNC server socket.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
97
diff
changeset
|
188 myRfb.stopReceiverTask(); |
97 | 189 inhelitClients(this, hostName); |
102
1f7ee648e1f6
inflator in MyRfbProtoProxy should be renew to accept new VNC server socket.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
97
diff
changeset
|
190 orderRecconection(hostName); |
59 | 191 } |
192 | |
97 | 193 |
194 | |
59 | 195 @Override |
196 public void settingsChanged(SettingsChangedEvent event) { | |
60 | 197 |
38 | 198 } |
61
d9cf08c6415c
During implementation change screen.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
60
diff
changeset
|
199 |
69 | 200 public void setFirstTime(boolean flag) { |
201 firstTime = flag; | |
202 } | |
203 | |
102
1f7ee648e1f6
inflator in MyRfbProtoProxy should be renew to accept new VNC server socket.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
97
diff
changeset
|
204 public void orderRecconection(String hostName) throws UnknownHostException, IOException, InterruptedException { |
1f7ee648e1f6
inflator in MyRfbProtoProxy should be renew to accept new VNC server socket.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
97
diff
changeset
|
205 myRfb.waitForReady(this); |
1f7ee648e1f6
inflator in MyRfbProtoProxy should be renew to accept new VNC server socket.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
97
diff
changeset
|
206 myRfb.sendDesktopSizeChange(); |
61
d9cf08c6415c
During implementation change screen.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
60
diff
changeset
|
207 } |
93 | 208 |
209 public LinkedList<String> clientList() { | |
210 return clients.getList(); | |
211 } | |
11 | 212 } |