Mercurial > hg > Applications > TightVNC_orginal
annotate src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java @ 35:1b81deb0abb3
write a little part reconnection.
author | one |
---|---|
date | Wed, 12 Sep 2012 13:16:47 +0900 |
parents | f70008073a03 |
children | 1454d6fe96c1 |
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; |
13 | 40 // public AcceptClient acc; |
11 | 41 public VncProxyService(Parser parser) { |
42 this(); | |
15 | 43 rfb = new MyRfbProtoProxy(); |
11 | 44 ParametersHandler.completeSettingsFromCLI(parser, connectionParams, settings, uiSettings); |
45 showControls = ParametersHandler.showControls; | |
46 passwordFromParams = parser.getValueFor(ParametersHandler.ARG_PASSWORD); | |
47 logger.info("TightVNC Viewer version " + ver()); | |
48 isApplet = false; | |
49 } | |
50 | |
51 public VncProxyService() { | |
52 connectionParams = new ParametersHandler.ConnectionParams(); | |
53 settings = ProtocolSettings.getDefaultSettings(); | |
54 uiSettings = super.uiSettings; | |
55 } | |
56 | |
57 boolean isClient = false; | |
58 public static final int DEFAULT_PORT = 5900; | |
59 public static Logger logger = Logger.getLogger("com.glavsoft"); | |
60 private boolean forceReconnection; | |
61 private String reconnectionReason; | |
62 private ConnectionParams connectionParams; | |
63 private final ProtocolSettings settings; | |
64 private final UiSettings uiSettings; | |
13 | 65 private AcceptClient aClient; |
66 private Thread bCast; | |
67 private Thread accThread; | |
68 private AcceptThread acceptThread; | |
69 private GetBroadCastProxy getCast; | |
11 | 70 |
71 | |
72 public static void main(String[] argv) { | |
73 String[] mainArgs = argv; | |
74 System.out.println(mainArgs.length); | |
75 // input into arguments Decision | |
76 | |
77 Parser parser = new Parser(); | |
78 ParametersHandler.completeParserOptions(parser); | |
79 | |
80 parser.parse(argv); | |
81 if (parser.isSet(ParametersHandler.ARG_HELP)) { | |
82 printUsage(parser.optionsUsage()); | |
83 System.exit(0); | |
84 } | |
85 VncProxyService vps = new VncProxyService(parser); | |
86 if (mainArgs.length != 0) { | |
87 for (int i = 0; i < argv.length; i++) { | |
88 vps.setArguments(mainArgs); | |
89 // write later | |
90 } | |
91 } else { | |
92 //getHostData(); | |
93 } | |
94 //SwingUtilities.invokeLater(myClient); | |
95 Thread th = new Thread(vps); | |
96 th.start(); | |
13 | 97 try { |
98 th.join(); | |
99 } catch (InterruptedException e) { | |
100 e.printStackTrace(); | |
101 } | |
102 vps.createConnection(); | |
103 vps.start_threads(); | |
11 | 104 } |
105 | |
106 private void setArguments(String[] mainArgs) { | |
107 } | |
108 | |
109 @Override | |
110 public void run() { | |
111 // getHostData(); | |
112 ConnectionManager connectionManager = new ConnectionManager(this, isApplet); | |
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); | |
13 | 136 aClient = new AcceptClient(connectionParams.hostName); |
137 Thread thread = new Thread(new CreateThread(aClient)); | |
138 thread.start(); | |
11 | 139 workingProtocol.handshake(); |
27 | 140 rfb.setProtocolContext(workingProtocol); |
13 | 141 |
11 | 142 // input into change parents |
143 ClipboardControllerImpl clipboardController = | |
144 new ClipboardControllerImpl(workingProtocol, settings.getRemoteCharsetName()); | |
145 clipboardController.setEnabled(settings.isAllowClipboardTransfer()); | |
146 settings.addListener(clipboardController); | |
13 | 147 |
19 | 148 surface = new Surface(workingProtocol, this, uiSettings.getScaleFactor()); // this method |
149 settings.addListener(this); | |
150 uiSettings.addListener(surface); | |
151 containerFrame = createContainer(); | |
152 connectionManager.setContainerFrame(containerFrame); | |
153 updateFrameTitle(); | |
23 | 154 |
16 | 155 |
156 workingProtocol.startNormalHandling(this, surface, clipboardController,rfb); | |
20
98519d16a8c3
getInitData from ProtocolContext
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
157 // rfb.setInitData(workingProtocol.getInitData()); too early |
16 | 158 // workingProtocol.startNormalHandling(this, surface, clipboardController); |
11 | 159 tryAgain = false; |
160 } catch (UnsupportedProtocolVersionException e) { | |
161 connectionManager.showReconnectDialog("Unsupported Protocol Version", e.getMessage()); | |
162 logger.severe(e.getMessage()); | |
163 } catch (UnsupportedSecurityTypeException e) { | |
164 connectionManager.showReconnectDialog("Unsupported Security Type", e.getMessage()); | |
165 logger.severe(e.getMessage()); | |
166 } catch (AuthenticationFailedException e) { | |
167 passwordFromParams = null; | |
168 connectionManager.showReconnectDialog("Authentication Failed", e.getMessage()); | |
169 logger.severe(e.getMessage()); | |
170 } catch (TransportException e) { | |
171 connectionManager.showReconnectDialog("Connection Error", "Connection Error" + ": " + e.getMessage()); | |
172 logger.severe(e.getMessage()); | |
173 } catch (IOException e) { | |
174 connectionManager.showReconnectDialog("Connection Error", "Connection Error" + ": " + e.getMessage()); | |
175 logger.severe(e.getMessage()); | |
176 } catch (FatalException e) { | |
177 connectionManager.showReconnectDialog("Connection Error", "Connection Error" + ": " + e.getMessage()); | |
178 logger.severe(e.getMessage()); | |
179 } | |
180 } | |
13 | 181 } |
182 | |
183 public void createConnection() { | |
184 rfb.selectPort(5999); | |
185 acceptThread = new AcceptThread(rfb, 5999); | |
186 accThread = new Thread(acceptThread); | |
187 getCast = new GetBroadCastProxy(this, | |
188 workingProtocol.getRemoteDesktopName(), | |
189 this.connectionParams.hostName); | |
190 bCast = new Thread(getCast); | |
191 } | |
192 | |
193 public void start_threads() { | |
194 //rfbThread.start(); | |
195 accThread.start(); | |
196 bCast.start(); | |
197 //rfb.requestThreadStart(); | |
11 | 198 } |
199 | |
34 | 200 public void proxyStart(String[] argv) { |
201 String[] mainArgs = argv; | |
202 System.out.println(mainArgs.length); | |
203 // input into arguments Decision | |
11 | 204 |
34 | 205 Parser parser = new Parser(); |
206 ParametersHandler.completeParserOptions(parser); | |
11 | 207 |
34 | 208 parser.parse(argv); |
209 if (parser.isSet(ParametersHandler.ARG_HELP)) { | |
210 printUsage(parser.optionsUsage()); | |
211 System.exit(0); | |
212 } | |
213 VncProxyService vps = new VncProxyService(parser); | |
214 if (mainArgs.length != 0) { | |
215 for (int i = 0; i < argv.length; i++) { | |
216 vps.setArguments(mainArgs); | |
217 // write later | |
218 } | |
219 } else { | |
220 //getHostData(); | |
221 } | |
222 //SwingUtilities.invokeLater(myClient); | |
223 Thread th = new Thread(vps); | |
224 th.start(); | |
225 try { | |
226 th.join(); | |
227 } catch (InterruptedException e) { | |
228 e.printStackTrace(); | |
229 } | |
230 vps.createConnection(); | |
231 vps.start_threads(); | |
232 } | |
233 | |
234 | |
11 | 235 @Override |
236 public void destroy() { | |
237 | |
238 } | |
239 | |
240 @Override | |
241 public void windowClosing(WindowEvent e) { | |
242 if (e != null && e.getComponent() != null) { | |
243 e.getWindow().setVisible(false); | |
244 } | |
245 closeApp(); | |
246 } | |
247 } |