Mercurial > hg > Applications > TightVNC_orginal
annotate src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java @ 20:98519d16a8c3
getInitData from ProtocolContext
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 29 Aug 2012 23:22:14 +0900 |
parents | ea83f4be0cc9 |
children | 6a4312344a5a |
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 | |
7 | |
13 | 8 |
11 | 9 import com.glavsoft.exceptions.AuthenticationFailedException; |
10 import com.glavsoft.exceptions.FatalException; | |
11 import com.glavsoft.exceptions.TransportException; | |
12 import com.glavsoft.exceptions.UnsupportedProtocolVersionException; | |
13 import com.glavsoft.exceptions.UnsupportedSecurityTypeException; | |
14 import com.glavsoft.rfb.IChangeSettingsListener; | |
15 import com.glavsoft.rfb.IRfbSessionListener; | |
16 import com.glavsoft.rfb.protocol.Protocol; | |
17 import com.glavsoft.rfb.protocol.ProtocolSettings; | |
18 import com.glavsoft.transport.Reader; | |
19 import com.glavsoft.transport.Writer; | |
20 import com.glavsoft.viewer.ConnectionManager; | |
21 import com.glavsoft.viewer.Viewer; | |
22 import com.glavsoft.viewer.cli.Parser; | |
23 import com.glavsoft.viewer.swing.ClipboardControllerImpl; | |
24 import com.glavsoft.viewer.swing.ParametersHandler; | |
16 | 25 import com.glavsoft.viewer.swing.Surface; |
11 | 26 import com.glavsoft.viewer.swing.UiSettings; |
27 import com.glavsoft.viewer.swing.ParametersHandler.ConnectionParams; | |
28 | |
29 public class VncProxyService extends Viewer implements Runnable, | |
30 IRfbSessionListener, IChangeSettingsListener { | |
31 | |
32 /** | |
33 * | |
34 */ | |
35 private static final long serialVersionUID = 1L; | |
36 | |
12 | 37 public MyRfbProtoProxy rfb; |
13 | 38 // public AcceptClient acc; |
11 | 39 public VncProxyService(Parser parser) { |
40 this(); | |
15 | 41 rfb = new MyRfbProtoProxy(); |
11 | 42 ParametersHandler.completeSettingsFromCLI(parser, connectionParams, settings, uiSettings); |
43 showControls = ParametersHandler.showControls; | |
44 passwordFromParams = parser.getValueFor(ParametersHandler.ARG_PASSWORD); | |
45 logger.info("TightVNC Viewer version " + ver()); | |
46 isApplet = false; | |
47 } | |
48 | |
49 public VncProxyService() { | |
50 connectionParams = new ParametersHandler.ConnectionParams(); | |
51 settings = ProtocolSettings.getDefaultSettings(); | |
52 uiSettings = super.uiSettings; | |
53 } | |
54 | |
55 boolean isClient = false; | |
56 public static final int DEFAULT_PORT = 5900; | |
57 public static Logger logger = Logger.getLogger("com.glavsoft"); | |
58 private boolean forceReconnection; | |
59 private String reconnectionReason; | |
60 private ConnectionParams connectionParams; | |
61 private final ProtocolSettings settings; | |
62 private final UiSettings uiSettings; | |
13 | 63 private AcceptClient aClient; |
64 private Thread bCast; | |
65 private Thread accThread; | |
66 private Thread rfbThread; | |
67 private AcceptThread acceptThread; | |
68 private GetBroadCastProxy getCast; | |
11 | 69 |
70 | |
71 public static void main(String[] argv) { | |
72 String[] mainArgs = argv; | |
73 System.out.println(mainArgs.length); | |
74 // input into arguments Decision | |
75 | |
76 Parser parser = new Parser(); | |
77 ParametersHandler.completeParserOptions(parser); | |
78 | |
79 parser.parse(argv); | |
80 if (parser.isSet(ParametersHandler.ARG_HELP)) { | |
81 printUsage(parser.optionsUsage()); | |
82 System.exit(0); | |
83 } | |
84 VncProxyService vps = new VncProxyService(parser); | |
85 if (mainArgs.length != 0) { | |
86 for (int i = 0; i < argv.length; i++) { | |
87 vps.setArguments(mainArgs); | |
88 // write later | |
89 } | |
90 } else { | |
91 //getHostData(); | |
92 } | |
93 //SwingUtilities.invokeLater(myClient); | |
94 Thread th = new Thread(vps); | |
95 th.start(); | |
13 | 96 try { |
97 th.join(); | |
98 } catch (InterruptedException e) { | |
99 e.printStackTrace(); | |
100 } | |
101 vps.createConnection(); | |
102 vps.start_threads(); | |
103 | |
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); |
12 | 121 workingSocket = connectionManager.connectToHost(connectionParams, settings); |
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(); |
13 | 140 |
11 | 141 // input into change parents |
142 ClipboardControllerImpl clipboardController = | |
143 new ClipboardControllerImpl(workingProtocol, settings.getRemoteCharsetName()); | |
144 clipboardController.setEnabled(settings.isAllowClipboardTransfer()); | |
145 settings.addListener(clipboardController); | |
13 | 146 |
19 | 147 surface = new Surface(workingProtocol, this, uiSettings.getScaleFactor()); // this method |
148 /* | |
149 settings.addListener(this); | |
150 uiSettings.addListener(surface); | |
151 containerFrame = createContainer(); | |
152 connectionManager.setContainerFrame(containerFrame); | |
153 updateFrameTitle(); | |
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 rfbThread = new Thread(this); | |
186 acceptThread = new AcceptThread(rfb, 5999); | |
187 accThread = new Thread(acceptThread); | |
188 getCast = new GetBroadCastProxy(this, | |
189 workingProtocol.getRemoteDesktopName(), | |
190 this.connectionParams.hostName); | |
191 bCast = new Thread(getCast); | |
192 } | |
193 | |
194 public void start_threads() { | |
195 //rfbThread.start(); | |
196 accThread.start(); | |
197 bCast.start(); | |
198 //rfb.requestThreadStart(); | |
11 | 199 } |
200 | |
201 | |
202 | |
203 @Override | |
204 public void destroy() { | |
205 | |
206 } | |
207 | |
208 | |
209 | |
210 @Override | |
211 public void windowClosing(WindowEvent e) { | |
212 if (e != null && e.getComponent() != null) { | |
213 e.getWindow().setVisible(false); | |
214 } | |
215 closeApp(); | |
216 } | |
217 } |