Mercurial > hg > Members > riono > TreeVNC_ja_comment
annotate src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java @ 31:872d9bcbfe56
Before changing the Viewer.
author | one |
---|---|
date | Sat, 01 Sep 2012 21:23:30 +0900 |
parents | 18fad65bc447 |
children | f70008073a03 |
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(); | |
104 | |
11 | 105 } |
106 | |
107 private void setArguments(String[] mainArgs) { | |
108 } | |
109 | |
110 @Override | |
111 public void run() { | |
112 // getHostData(); | |
113 ConnectionManager connectionManager = new ConnectionManager(this, isApplet); | |
114 if (forceReconnection) { | |
115 connectionManager.showReconnectDialog("Connection lost", reconnectionReason); | |
116 forceReconnection = false; | |
117 } | |
118 tryAgain = true; | |
119 while (tryAgain) { | |
13 | 120 // connectionParams.hostName = arguments[0]; |
11 | 121 // workingSocket = connectionManager.connectToTreeHost(connectionParams, settings); |
12 | 122 workingSocket = connectionManager.connectToHost(connectionParams, settings); |
11 | 123 if (null == workingSocket) { |
124 closeApp(); | |
125 break; | |
126 } | |
127 logger.info("Connected"); | |
128 | |
129 try { | |
130 workingSocket.setTcpNoDelay(true); // disable Nagle algorithm | |
131 Reader reader = new Reader(workingSocket.getInputStream()); | |
132 Writer writer = new Writer(workingSocket.getOutputStream()); | |
19 | 133 // rfb.setStream(reader,writer); |
11 | 134 workingProtocol = new Protocol(reader, writer, |
135 new PasswordChooser(passwordFromParams, connectionParams, containerFrame, this), | |
136 settings); | |
13 | 137 aClient = new AcceptClient(connectionParams.hostName); |
138 Thread thread = new Thread(new CreateThread(aClient)); | |
139 thread.start(); | |
11 | 140 workingProtocol.handshake(); |
27 | 141 rfb.setProtocolContext(workingProtocol); |
13 | 142 |
11 | 143 // input into change parents |
144 ClipboardControllerImpl clipboardController = | |
145 new ClipboardControllerImpl(workingProtocol, settings.getRemoteCharsetName()); | |
146 clipboardController.setEnabled(settings.isAllowClipboardTransfer()); | |
147 settings.addListener(clipboardController); | |
13 | 148 |
19 | 149 surface = new Surface(workingProtocol, this, uiSettings.getScaleFactor()); // this method |
150 settings.addListener(this); | |
151 uiSettings.addListener(surface); | |
152 containerFrame = createContainer(); | |
153 connectionManager.setContainerFrame(containerFrame); | |
154 updateFrameTitle(); | |
23 | 155 |
16 | 156 |
157 workingProtocol.startNormalHandling(this, surface, clipboardController,rfb); | |
20
98519d16a8c3
getInitData from ProtocolContext
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
158 // rfb.setInitData(workingProtocol.getInitData()); too early |
16 | 159 // workingProtocol.startNormalHandling(this, surface, clipboardController); |
11 | 160 tryAgain = false; |
161 } catch (UnsupportedProtocolVersionException e) { | |
162 connectionManager.showReconnectDialog("Unsupported Protocol Version", e.getMessage()); | |
163 logger.severe(e.getMessage()); | |
164 } catch (UnsupportedSecurityTypeException e) { | |
165 connectionManager.showReconnectDialog("Unsupported Security Type", e.getMessage()); | |
166 logger.severe(e.getMessage()); | |
167 } catch (AuthenticationFailedException e) { | |
168 passwordFromParams = null; | |
169 connectionManager.showReconnectDialog("Authentication Failed", e.getMessage()); | |
170 logger.severe(e.getMessage()); | |
171 } catch (TransportException e) { | |
172 connectionManager.showReconnectDialog("Connection Error", "Connection Error" + ": " + e.getMessage()); | |
173 logger.severe(e.getMessage()); | |
174 } catch (IOException e) { | |
175 connectionManager.showReconnectDialog("Connection Error", "Connection Error" + ": " + e.getMessage()); | |
176 logger.severe(e.getMessage()); | |
177 } catch (FatalException e) { | |
178 connectionManager.showReconnectDialog("Connection Error", "Connection Error" + ": " + e.getMessage()); | |
179 logger.severe(e.getMessage()); | |
180 } | |
181 } | |
13 | 182 } |
183 | |
184 public void createConnection() { | |
185 rfb.selectPort(5999); | |
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 } |