diff src/viewer_swing/java/com/glavsoft/viewer/TreeConnectionManager.java @ 11:57ae9fbb1245

add files
author Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
date Tue, 21 Aug 2012 14:02:05 +0900
parents
children 12c3a73be47f
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/viewer_swing/java/com/glavsoft/viewer/TreeConnectionManager.java	Tue Aug 21 14:02:05 2012 +0900
@@ -0,0 +1,67 @@
+package com.glavsoft.viewer;
+
+import java.awt.event.WindowListener;
+import java.io.IOException;
+import java.net.Socket;
+import java.net.UnknownHostException;
+
+import ac.ryukyu.treevnc.client.GetDataClient;
+import ac.ryukyu.treevnc.client.GetHostClient;
+
+import com.glavsoft.rfb.protocol.ProtocolSettings;
+import com.glavsoft.viewer.swing.ParametersHandler;
+
+public class TreeConnectionManager extends ConnectionManager {
+	
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 1L;
+	public TreeConnectionManager(WindowListener appWindowListener,
+			boolean isApplet) {
+		super(appWindowListener, isApplet);
+	}
+	
+	@Override
+	public Socket connectToHost(final ParametersHandler.ConnectionParams connectionParams, ProtocolSettings settings) {
+		Socket socket = null;
+		boolean wasError = false;
+		GetHostClient bCast = new GetHostClient("who");
+		bCast.createSocket();
+		bCast.sendData();
+		GetDataClient getBcast = new GetDataClient();
+		Thread runBcast = new Thread(getBcast);
+		runBcast.start();
+		getBcast.setStopFlag(true);
+		//connectionParams.hostName = getBcast.textAddress();
+		if("notFound".equals(connectionParams.hostName)) {
+			getBcast.text.ipRegister();
+			connectionParams.hostName = getBcast.textAddress();
+			connectionParams.portNumber = Integer.parseInt(getBcast.textPort());
+			//connectionParams.portNumber = 5900;
+		} else {
+			// connectionParams.portNumber = Integer.parseInt(getBcast.textPort());
+			connectionParams.portNumber = 5900;
+		}
+			Viewer.logger.info("Connecting to host " + connectionParams.hostName + ":" + connectionParams.portNumber);
+			try {
+				socket = new Socket(connectionParams.hostName, connectionParams.portNumber);
+				wasError = false;
+			} catch (UnknownHostException e) {
+				Viewer.logger.severe("Unknown host: " + connectionParams.hostName);
+				showConnectionErrorDialog("Unknown host: '" + connectionParams.hostName + "'");
+				wasError = true;
+			} catch (IOException e) {
+				Viewer.logger.severe("Couldn't connect to: " +
+						connectionParams.hostName + ":" + connectionParams.portNumber +
+						": " + e.getMessage());
+				showConnectionErrorDialog("Couldn't connect to: '" + connectionParams.hostName +
+						"'\n" + e.getMessage());
+				wasError = true;
+			}
+		return socket;
+	}
+	
+
+
+}