Mercurial > hg > Applications > TightVNC_orginal
comparison src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java @ 38:c2f0b6907448
add doc directory
author | one |
---|---|
date | Thu, 27 Sep 2012 19:32:25 +0900 |
parents | 1454d6fe96c1 |
children | 3c072f2f39bb |
comparison
equal
deleted
inserted
replaced
37:1454d6fe96c1 | 38:c2f0b6907448 |
---|---|
1 package jp.ac.u_ryukyu.treevnc.server; | 1 package jp.ac.u_ryukyu.treevnc.server; |
2 | 2 |
3 import java.awt.event.*; | 3 import java.awt.event.*; |
4 import java.io.*; | 4 import java.io.*; |
5 import java.net.Socket; | |
6 import java.net.UnknownHostException; | |
7 import java.util.LinkedList; | |
5 import java.util.logging.Logger; | 8 import java.util.logging.Logger; |
6 | 9 |
7 import jp.ac.u_ryukyu.treevnc.AcceptThread; | 10 import jp.ac.u_ryukyu.treevnc.AcceptThread; |
8 | 11 |
9 | 12 |
36 */ | 39 */ |
37 private static final long serialVersionUID = 1L; | 40 private static final long serialVersionUID = 1L; |
38 | 41 |
39 public MyRfbProtoProxy rfb; | 42 public MyRfbProtoProxy rfb; |
40 private ConnectionManager connectionManager; | 43 private ConnectionManager connectionManager; |
44 private VncProxyService vps; | |
45 private CreateThread createThread; | |
46 AcceptClient aClient; | |
47 private int port; | |
41 // public AcceptClient acc; | 48 // public AcceptClient acc; |
42 public VncProxyService(Parser parser) { | 49 public VncProxyService(Parser parser) { |
43 this(); | 50 this(); |
44 rfb = new MyRfbProtoProxy(); | |
45 ParametersHandler.completeSettingsFromCLI(parser, connectionParams, settings, uiSettings); | 51 ParametersHandler.completeSettingsFromCLI(parser, connectionParams, settings, uiSettings); |
46 showControls = ParametersHandler.showControls; | 52 showControls = ParametersHandler.showControls; |
47 passwordFromParams = parser.getValueFor(ParametersHandler.ARG_PASSWORD); | 53 passwordFromParams = parser.getValueFor(ParametersHandler.ARG_PASSWORD); |
48 logger.info("TightVNC Viewer version " + ver()); | 54 logger.info("TightVNC Viewer version " + ver()); |
49 isApplet = false; | 55 isApplet = false; |
50 } | 56 } |
51 | 57 |
52 public VncProxyService() { | 58 public VncProxyService() { |
59 rfb = new MyRfbProtoProxy(); | |
60 aClient = new AcceptClient(); | |
53 connectionManager = new ConnectionManager(this, isApplet); | 61 connectionManager = new ConnectionManager(this, isApplet); |
54 connectionParams = new ParametersHandler.ConnectionParams(); | 62 connectionParams = new ParametersHandler.ConnectionParams(); |
55 settings = ProtocolSettings.getDefaultSettings(); | 63 settings = ProtocolSettings.getDefaultSettings(); |
56 uiSettings = super.uiSettings; | 64 uiSettings = super.uiSettings; |
57 } | 65 } |
62 private boolean forceReconnection; | 70 private boolean forceReconnection; |
63 private String reconnectionReason; | 71 private String reconnectionReason; |
64 private ConnectionParams connectionParams; | 72 private ConnectionParams connectionParams; |
65 private final ProtocolSettings settings; | 73 private final ProtocolSettings settings; |
66 private final UiSettings uiSettings; | 74 private final UiSettings uiSettings; |
67 private Thread bCast; | |
68 private Thread accThread; | |
69 private AcceptThread acceptThread; | 75 private AcceptThread acceptThread; |
70 private GetBroadCastProxy getCast; | 76 private GetBroadCastProxy getCast; |
71 | 77 |
72 | 78 |
73 public static void main(String[] argv) { | 79 public static void main(String[] argv) { |
98 try { | 104 try { |
99 th.join(); | 105 th.join(); |
100 } catch (InterruptedException e) { | 106 } catch (InterruptedException e) { |
101 e.printStackTrace(); | 107 e.printStackTrace(); |
102 } | 108 } |
103 vps.createConnection(); | 109 vps.createConnectionAndStart(); |
104 vps.start_threads(); | |
105 } | 110 } |
106 | 111 |
107 private void setArguments(String[] mainArgs) { | 112 private void setArguments(String[] mainArgs) { |
108 } | 113 } |
109 | 114 |
131 Writer writer = new Writer(workingSocket.getOutputStream()); | 136 Writer writer = new Writer(workingSocket.getOutputStream()); |
132 // rfb.setStream(reader,writer); | 137 // rfb.setStream(reader,writer); |
133 workingProtocol = new Protocol(reader, writer, | 138 workingProtocol = new Protocol(reader, writer, |
134 new PasswordChooser(passwordFromParams, connectionParams, containerFrame, this), | 139 new PasswordChooser(passwordFromParams, connectionParams, containerFrame, this), |
135 settings); | 140 settings); |
136 threadSetAndStart(); | |
137 workingProtocol.handshake(); | 141 workingProtocol.handshake(); |
138 rfb.setProtocolContext(workingProtocol); | 142 rfb.setProtocolContext(workingProtocol); |
143 threadSetAndStart(); | |
139 // input into change parents | 144 // input into change parents |
140 ClipboardControllerImpl clipboardController = | 145 ClipboardControllerImpl clipboardController = |
141 new ClipboardControllerImpl(workingProtocol, settings.getRemoteCharsetName()); | 146 new ClipboardControllerImpl(workingProtocol, settings.getRemoteCharsetName()); |
142 clipboardController.setEnabled(settings.isAllowClipboardTransfer()); | 147 clipboardController.setEnabled(settings.isAllowClipboardTransfer()); |
143 settings.addListener(clipboardController); | 148 settings.addListener(clipboardController); |
174 logger.severe(e.getMessage()); | 179 logger.severe(e.getMessage()); |
175 } | 180 } |
176 } | 181 } |
177 } | 182 } |
178 | 183 |
179 public void createConnection() { | 184 public void createConnectionAndStart() { |
180 rfb.selectPort(5999); | 185 port = rfb.selectPort(5999); |
181 acceptThread = new AcceptThread(rfb, 5999); | 186 acceptThread = new AcceptThread(rfb, port); |
182 accThread = new Thread(acceptThread); | 187 Thread thread = new Thread(acceptThread); |
188 thread.start(); | |
183 getCast = new GetBroadCastProxy(this, | 189 getCast = new GetBroadCastProxy(this, |
184 workingProtocol.getRemoteDesktopName(), | 190 workingProtocol.getRemoteDesktopName(), |
185 this.connectionParams.hostName); | 191 this.connectionParams.hostName); |
186 bCast = new Thread(getCast); | 192 thread = new Thread(getCast); |
193 thread.start(); | |
187 } | 194 } |
188 | 195 |
189 public void start_threads() { | 196 public void start_threads() { |
190 //rfbThread.start(); | 197 //rfbThread.start(); |
191 accThread.start(); | |
192 bCast.start(); | |
193 //rfb.requestThreadStart(); | 198 //rfb.requestThreadStart(); |
194 } | 199 } |
195 | 200 |
196 public void proxyStart(String[] argv) { | 201 public void proxyStart(String[] argv) { |
197 String[] mainArgs = argv; | 202 String[] mainArgs = argv; |
204 parser.parse(argv); | 209 parser.parse(argv); |
205 if (parser.isSet(ParametersHandler.ARG_HELP)) { | 210 if (parser.isSet(ParametersHandler.ARG_HELP)) { |
206 printUsage(parser.optionsUsage()); | 211 printUsage(parser.optionsUsage()); |
207 System.exit(0); | 212 System.exit(0); |
208 } | 213 } |
209 VncProxyService vps = new VncProxyService(parser); | 214 vps = new VncProxyService(parser); |
210 if (mainArgs.length != 0) { | 215 if (mainArgs.length != 0) { |
211 for (int i = 0; i < argv.length; i++) { | 216 for (int i = 0; i < argv.length; i++) { |
212 vps.setArguments(mainArgs); | 217 vps.setArguments(mainArgs); |
213 // write later | 218 // write later |
214 } | 219 } |
221 try { | 226 try { |
222 th.join(); | 227 th.join(); |
223 } catch (InterruptedException e) { | 228 } catch (InterruptedException e) { |
224 e.printStackTrace(); | 229 e.printStackTrace(); |
225 } | 230 } |
226 vps.createConnection(); | 231 vps.createConnectionAndStart(); |
227 vps.start_threads(); | |
228 } | 232 } |
229 | 233 |
230 | 234 |
231 @Override | 235 @Override |
232 public void destroy() { | 236 public void destroy() { |
239 e.getWindow().setVisible(false); | 243 e.getWindow().setVisible(false); |
240 } | 244 } |
241 closeApp(); | 245 closeApp(); |
242 } | 246 } |
243 | 247 |
244 private void threadSetAndStart() { | 248 private void threadSetAndStart() throws UnknownHostException, IOException { |
245 AcceptClient aClient = new AcceptClient(connectionParams.hostName); | 249 //aClient = new AcceptClient(); |
246 Thread thread = new Thread(new CreateThread(aClient)); | 250 createThread = new CreateThread(aClient); |
247 thread.start(); | 251 Thread thread = new Thread(createThread); |
248 thread = new Thread(new ChangeHost(this, forceReconnection)); | 252 thread.start(); |
249 thread.start(); | 253 thread = new Thread(new ChangeHost(new VncProxyService(), forceReconnection,this)); |
250 | 254 thread.start(); |
255 // createSocketAndSend(aClient.getList(),String.valueOf(port)); | |
251 } | 256 } |
252 | 257 |
253 public void setConnectionManager(ConnectionManager _connectionManager) { | 258 public void setConnectionManager(ConnectionManager _connectionManager) { |
254 connectionManager = _connectionManager; | 259 connectionManager = _connectionManager; |
255 } | 260 } |
261 | |
262 protected void socketClose() { | |
263 try { | |
264 workingSocket.close(); | |
265 acceptThread.flag=true; | |
266 getCast.setStopFlag(true); | |
267 //createThread.setStopFlag(true); | |
268 } catch (IOException e) {/*nop*/} | |
269 } | |
270 | |
271 @Override | |
272 public void rfbSessionStopped(final String reason) { | |
273 if (workingSocket != null && workingSocket.isConnected()) { | |
274 try { | |
275 workingSocket.close(); | |
276 } catch (IOException e) { /*nop*/ } | |
277 } | |
278 } | |
279 | |
280 private void createSocketAndSend(LinkedList<String> clientList,String port) throws UnknownHostException, IOException { | |
281 int i = 0; | |
282 for(String client : clientList) { | |
283 if(i!=0) { | |
284 Socket echoSocket; | |
285 echoSocket = new Socket(client, 10001); | |
286 DataOutputStream os = new DataOutputStream(echoSocket.getOutputStream()); | |
287 os.writeBytes("reconnection\n"); | |
288 os.writeBytes(port+"\n"); | |
289 os.close(); | |
290 } | |
291 i++; | |
292 } | |
293 } | |
294 | |
295 public void changeVNCServer() { | |
296 // sender and re | |
297 workingProtocol.cleanUpSession(); | |
298 } | |
256 } | 299 } |