Mercurial > hg > Applications > TightVNC_orginal
annotate src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java @ 37:1454d6fe96c1
add Changehost.java
author | one |
---|---|
date | Wed, 19 Sep 2012 19:08:07 +0900 |
parents | 1b81deb0abb3 |
children | c2f0b6907448 |
rev | line source |
---|---|
12 | 1 package jp.ac.u_ryukyu.treevnc.server; |
11 | 2 |
3 import java.awt.event.*; | |
4 import java.io.*; | |
5 import java.util.logging.Logger; | |
6 | |
31 | 7 import jp.ac.u_ryukyu.treevnc.AcceptThread; |
8 | |
11 | 9 |
13 | 10 |
11 | 11 import com.glavsoft.exceptions.AuthenticationFailedException; |
12 import com.glavsoft.exceptions.FatalException; | |
13 import com.glavsoft.exceptions.TransportException; | |
14 import com.glavsoft.exceptions.UnsupportedProtocolVersionException; | |
15 import com.glavsoft.exceptions.UnsupportedSecurityTypeException; | |
16 import com.glavsoft.rfb.IChangeSettingsListener; | |
17 import com.glavsoft.rfb.IRfbSessionListener; | |
18 import com.glavsoft.rfb.protocol.Protocol; | |
19 import com.glavsoft.rfb.protocol.ProtocolSettings; | |
20 import com.glavsoft.transport.Reader; | |
21 import com.glavsoft.transport.Writer; | |
22 import com.glavsoft.viewer.ConnectionManager; | |
23 import com.glavsoft.viewer.Viewer; | |
24 import com.glavsoft.viewer.cli.Parser; | |
25 import com.glavsoft.viewer.swing.ClipboardControllerImpl; | |
26 import com.glavsoft.viewer.swing.ParametersHandler; | |
16 | 27 import com.glavsoft.viewer.swing.Surface; |
11 | 28 import com.glavsoft.viewer.swing.UiSettings; |
29 import com.glavsoft.viewer.swing.ParametersHandler.ConnectionParams; | |
30 | |
31 public class VncProxyService extends Viewer implements Runnable, | |
32 IRfbSessionListener, IChangeSettingsListener { | |
33 | |
34 /** | |
35 * | |
36 */ | |
37 private static final long serialVersionUID = 1L; | |
38 | |
12 | 39 public MyRfbProtoProxy rfb; |
37 | 40 private ConnectionManager connectionManager; |
13 | 41 // public AcceptClient acc; |
11 | 42 public VncProxyService(Parser parser) { |
43 this(); | |
15 | 44 rfb = new MyRfbProtoProxy(); |
11 | 45 ParametersHandler.completeSettingsFromCLI(parser, connectionParams, settings, uiSettings); |
46 showControls = ParametersHandler.showControls; | |
47 passwordFromParams = parser.getValueFor(ParametersHandler.ARG_PASSWORD); | |
48 logger.info("TightVNC Viewer version " + ver()); | |
49 isApplet = false; | |
50 } | |
51 | |
52 public VncProxyService() { | |
37 | 53 connectionManager = new ConnectionManager(this, isApplet); |
11 | 54 connectionParams = new ParametersHandler.ConnectionParams(); |
55 settings = ProtocolSettings.getDefaultSettings(); | |
56 uiSettings = super.uiSettings; | |
57 } | |
58 | |
59 boolean isClient = false; | |
60 public static final int DEFAULT_PORT = 5900; | |
61 public static Logger logger = Logger.getLogger("com.glavsoft"); | |
62 private boolean forceReconnection; | |
63 private String reconnectionReason; | |
64 private ConnectionParams connectionParams; | |
65 private final ProtocolSettings settings; | |
66 private final UiSettings uiSettings; | |
13 | 67 private Thread bCast; |
68 private Thread accThread; | |
69 private AcceptThread acceptThread; | |
70 private GetBroadCastProxy getCast; | |
11 | 71 |
72 | |
73 public static void main(String[] argv) { | |
74 String[] mainArgs = argv; | |
75 System.out.println(mainArgs.length); | |
76 // input into arguments Decision | |
77 | |
78 Parser parser = new Parser(); | |
79 ParametersHandler.completeParserOptions(parser); | |
80 | |
81 parser.parse(argv); | |
82 if (parser.isSet(ParametersHandler.ARG_HELP)) { | |
83 printUsage(parser.optionsUsage()); | |
84 System.exit(0); | |
85 } | |
86 VncProxyService vps = new VncProxyService(parser); | |
87 if (mainArgs.length != 0) { | |
88 for (int i = 0; i < argv.length; i++) { | |
89 vps.setArguments(mainArgs); | |
90 // write later | |
91 } | |
92 } else { | |
93 //getHostData(); | |
94 } | |
95 //SwingUtilities.invokeLater(myClient); | |
96 Thread th = new Thread(vps); | |
97 th.start(); | |
13 | 98 try { |
99 th.join(); | |
100 } catch (InterruptedException e) { | |
101 e.printStackTrace(); | |
102 } | |
103 vps.createConnection(); | |
104 vps.start_threads(); | |
11 | 105 } |
106 | |
107 private void setArguments(String[] mainArgs) { | |
108 } | |
109 | |
110 @Override | |
111 public void run() { | |
112 // getHostData(); | |
113 if (forceReconnection) { | |
114 connectionManager.showReconnectDialog("Connection lost", reconnectionReason); | |
115 forceReconnection = false; | |
116 } | |
117 tryAgain = true; | |
118 while (tryAgain) { | |
13 | 119 // connectionParams.hostName = arguments[0]; |
11 | 120 // workingSocket = connectionManager.connectToTreeHost(connectionParams, settings); |
35 | 121 workingSocket = connectionManager.connectToHost(connectionParams, settings, rfb); |
11 | 122 if (null == workingSocket) { |
123 closeApp(); | |
124 break; | |
125 } | |
126 logger.info("Connected"); | |
127 | |
128 try { | |
129 workingSocket.setTcpNoDelay(true); // disable Nagle algorithm | |
130 Reader reader = new Reader(workingSocket.getInputStream()); | |
131 Writer writer = new Writer(workingSocket.getOutputStream()); | |
19 | 132 // rfb.setStream(reader,writer); |
11 | 133 workingProtocol = new Protocol(reader, writer, |
134 new PasswordChooser(passwordFromParams, connectionParams, containerFrame, this), | |
135 settings); | |
37 | 136 threadSetAndStart(); |
11 | 137 workingProtocol.handshake(); |
27 | 138 rfb.setProtocolContext(workingProtocol); |
11 | 139 // input into change parents |
140 ClipboardControllerImpl clipboardController = | |
141 new ClipboardControllerImpl(workingProtocol, settings.getRemoteCharsetName()); | |
142 clipboardController.setEnabled(settings.isAllowClipboardTransfer()); | |
143 settings.addListener(clipboardController); | |
19 | 144 surface = new Surface(workingProtocol, this, uiSettings.getScaleFactor()); // this method |
145 settings.addListener(this); | |
146 uiSettings.addListener(surface); | |
147 containerFrame = createContainer(); | |
148 connectionManager.setContainerFrame(containerFrame); | |
149 updateFrameTitle(); | |
37 | 150 containerFrame.dispose(); |
151 containerFrame = null; | |
16 | 152 workingProtocol.startNormalHandling(this, surface, clipboardController,rfb); |
20
98519d16a8c3
getInitData from ProtocolContext
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
153 // rfb.setInitData(workingProtocol.getInitData()); too early |
16 | 154 // workingProtocol.startNormalHandling(this, surface, clipboardController); |
11 | 155 tryAgain = false; |
156 } catch (UnsupportedProtocolVersionException e) { | |
157 connectionManager.showReconnectDialog("Unsupported Protocol Version", e.getMessage()); | |
158 logger.severe(e.getMessage()); | |
159 } catch (UnsupportedSecurityTypeException e) { | |
160 connectionManager.showReconnectDialog("Unsupported Security Type", e.getMessage()); | |
161 logger.severe(e.getMessage()); | |
162 } catch (AuthenticationFailedException e) { | |
163 passwordFromParams = null; | |
164 connectionManager.showReconnectDialog("Authentication Failed", e.getMessage()); | |
165 logger.severe(e.getMessage()); | |
166 } catch (TransportException e) { | |
167 connectionManager.showReconnectDialog("Connection Error", "Connection Error" + ": " + e.getMessage()); | |
168 logger.severe(e.getMessage()); | |
169 } catch (IOException e) { | |
170 connectionManager.showReconnectDialog("Connection Error", "Connection Error" + ": " + e.getMessage()); | |
171 logger.severe(e.getMessage()); | |
172 } catch (FatalException e) { | |
173 connectionManager.showReconnectDialog("Connection Error", "Connection Error" + ": " + e.getMessage()); | |
174 logger.severe(e.getMessage()); | |
175 } | |
176 } | |
13 | 177 } |
178 | |
179 public void createConnection() { | |
180 rfb.selectPort(5999); | |
181 acceptThread = new AcceptThread(rfb, 5999); | |
182 accThread = new Thread(acceptThread); | |
183 getCast = new GetBroadCastProxy(this, | |
184 workingProtocol.getRemoteDesktopName(), | |
185 this.connectionParams.hostName); | |
186 bCast = new Thread(getCast); | |
187 } | |
188 | |
189 public void start_threads() { | |
190 //rfbThread.start(); | |
191 accThread.start(); | |
192 bCast.start(); | |
193 //rfb.requestThreadStart(); | |
11 | 194 } |
195 | |
34 | 196 public void proxyStart(String[] argv) { |
197 String[] mainArgs = argv; | |
198 System.out.println(mainArgs.length); | |
199 // input into arguments Decision | |
11 | 200 |
34 | 201 Parser parser = new Parser(); |
202 ParametersHandler.completeParserOptions(parser); | |
11 | 203 |
34 | 204 parser.parse(argv); |
205 if (parser.isSet(ParametersHandler.ARG_HELP)) { | |
206 printUsage(parser.optionsUsage()); | |
207 System.exit(0); | |
208 } | |
209 VncProxyService vps = new VncProxyService(parser); | |
210 if (mainArgs.length != 0) { | |
211 for (int i = 0; i < argv.length; i++) { | |
212 vps.setArguments(mainArgs); | |
213 // write later | |
214 } | |
215 } else { | |
216 //getHostData(); | |
217 } | |
218 //SwingUtilities.invokeLater(myClient); | |
219 Thread th = new Thread(vps); | |
220 th.start(); | |
221 try { | |
222 th.join(); | |
223 } catch (InterruptedException e) { | |
224 e.printStackTrace(); | |
225 } | |
226 vps.createConnection(); | |
227 vps.start_threads(); | |
228 } | |
229 | |
230 | |
11 | 231 @Override |
232 public void destroy() { | |
233 | |
234 } | |
235 | |
236 @Override | |
237 public void windowClosing(WindowEvent e) { | |
238 if (e != null && e.getComponent() != null) { | |
239 e.getWindow().setVisible(false); | |
240 } | |
241 closeApp(); | |
242 } | |
37 | 243 |
244 private void threadSetAndStart() { | |
245 AcceptClient aClient = new AcceptClient(connectionParams.hostName); | |
246 Thread thread = new Thread(new CreateThread(aClient)); | |
247 thread.start(); | |
248 thread = new Thread(new ChangeHost(this, forceReconnection)); | |
249 thread.start(); | |
250 | |
251 } | |
252 | |
253 public void setConnectionManager(ConnectionManager _connectionManager) { | |
254 connectionManager = _connectionManager; | |
255 } | |
11 | 256 } |