example launch the vnc by tightvnc java library

example launch the vnc by tightvnc java library

2013/05/20 Openstack 0

After a few hours hack into the tightvnc code, i can display the vnc onto a JPanel, i will replace the buggy novnc with my own vnc proxy server, so user don’t need to setup the novnc for openstack but able to remote to every instance using openstack.

Viewer viewer = new Viewer();
		try {
			Socket workingSocket = new Socket("", 9401);
			workingSocket.setTcpNoDelay(true); // disable Nagle algorithm
			Reader reader = new Reader(workingSocket.getInputStream());
			Writer writer = new Writer(workingSocket.getOutputStream());
			ProtocolSettings rfbSettings = ProtocolSettings.getDefaultSettings();
			Protocol workingProtocol = new Protocol(reader, writer, new PeterIPasswordRetriever(), rfbSettings);

			UiSettings uiSettings = new UiSettings();

			boolean hasJsch = true;
			boolean allowInteractive = false;//allowAppletInteractiveConnections || ! isApplet;
			ConnectionPresenter connectionPresenter = new ConnectionPresenter(hasJsch, allowInteractive);
			ConnectionParams connectionParams = new ConnectionParams();
			connectionPresenter.addModel("ConnectionParamsModel", connectionParams);

			final ConnectionView connectionView = new ConnectionView(TightVNC.this, // appWindowListener
					connectionPresenter, hasJsch);

			SwingViewerWindow viewerWindow = createViewerWindow(workingProtocol, rfbSettings, uiSettings, "p:9401", connectionPresenter);

			SwingViewerWindowFactory viewerWindowFactory = new SwingViewerWindowFactory(true, false, viewer);
			connectionPresenter.setConnectionWorkerFactory(new SwingConnectionWorkerFactory(connectionView.getFrame(), "mypassword", connectionPresenter, viewerWindowFactory));

			connectionPresenter.startConnection(rfbSettings, uiSettings, 0);
		} catch (Exception ex) {


	class PeterIPasswordRetriever implements IPasswordRetriever {

		public String getPassword() {
			return "mypassword";