diff src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java @ 205:614db20d8fab

try to separate Network management
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 02 Jul 2014 16:31:25 +0900
parents d9d234715853
children 2b3eb4a9492f
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java	Fri Jun 27 21:37:20 2014 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java	Wed Jul 02 16:31:25 2014 +0900
@@ -62,12 +62,11 @@
     private boolean hasViewer = false;
     private boolean reconnecting;
     private short reconnectingId;  // Change Server Request to id's node VNC server
-	private HashMap<String, TreeManagement> interfaces = new HashMap<String, TreeManagement>();
-	private String vncInterface;
-
+    private TreeVNCNetwork nets = new TreeVNCNetwork();
 
 	public MyRfbProto() {
 		rThread = new RequestScreenThread(this);
+		nets.setMyRfb(this);
 	}
 	
 	abstract public boolean isTreeManager() ;
@@ -361,7 +360,7 @@
 	    	NetworkInterface ni = getInterface(vncSocket);
 	    	if (ni!=null) {
 	    		vncInterface = ni.getName();
-	    		System.out.println("VNCNetworkInterface :" + ni.getName());
+	    		System.out.println("VNCNetworkInterface :" + vncInterface);
 	    	}
 	        sendDesktopSizeChange(reconnectingId);
 	        reconnecting = false;
@@ -377,14 +376,6 @@
 	    }
 	}	
 
-	private NetworkInterface getInterface(Socket vncSocket) {
-		InetAddress address = vncSocket.getInetAddress();
-		try {
-			return NetworkInterface.getByInetAddress(address);
-		} catch (SocketException e) {
-			return null;
-		}
-	}
 
 	public synchronized void waitForVNCConnection() throws InterruptedException {
 	    if (reconnectingId!=0) {
@@ -706,23 +697,5 @@
 		return reconnectingId;
 	}
 
-	public void getNetworkInterfaces() throws SocketException {
-		for (Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces(); e.hasMoreElements();) {
-			NetworkInterface ni;
-			ni = e.nextElement();
-			if (ni.isUp() && ni.supportsMulticast() && !ni.isLoopback()) {
-		        String hostName = ni.getInetAddresses().nextElement().getHostAddress();
-                TreeManagement treeManager = new TreeManagement(hostName, ConnectionParams.DEFAULT_VNC_ROOT, viewer.getShowTree());
-                treeManager.getList().getFirst().setPort(getAcceptPort());
-				addNetworkInterface(ni, treeManager);    			
-				System.out.println("Interfaces :" + ni.getName());
-			}
-		}
-	}
-
-	private void addNetworkInterface(NetworkInterface ni, TreeManagement treeManager) {
-		interfaces.put(ni.getName(), treeManager);
-	}
-
 	
 }