diff src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java @ 202:22676ca0dd97

get VNC Socket.
author oc
date Fri, 27 Jun 2014 19:21:18 +0900
parents ced24de3f2c5
children 2f6237fea67e
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java	Fri Jun 27 18:50:49 2014 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java	Fri Jun 27 19:21:18 2014 +0900
@@ -72,7 +72,7 @@
 		rThread = new RequestScreenThread(this);
 	}
 	
-	abstract public boolean isRoot() ;
+	abstract public boolean isTreeManager() ;
 	
 	public ProtocolContext getContext() {
 		return context;
@@ -148,7 +148,7 @@
 						final int c = is.readByte(b);
 						if (c <= 0)
 							throw new IOException();
-						if (isRoot()) {
+						if (isTreeManager()) {
 							if (b[0] == ClientToServerMessage.SERVER_CHANGE_REQUEST) {
 								if (permitChangeScreen()) {
 									ByteBuffer buf = ByteBuffer.wrap(b);
@@ -357,8 +357,13 @@
 		
 	}
 
-	public synchronized void setReadyReconnect(boolean ready) {
+	public synchronized void vncConnected(boolean ready) {
 	    if (ready && reconnecting) {
+	    	Socket vncSocket = viewer.getVNCSocket();
+	    	NetworkInterface ni = getInterface(vncSocket);
+	    	if (ni!=null) {
+	    		System.out.println("VNCNetworkInterface :" + ni.getName());
+	    	}
 	        sendDesktopSizeChange(reconnectingId);
 	        reconnecting = false;
 	        if (reconnectingId == 0) {
@@ -373,7 +378,16 @@
 	    }
 	}	
 
-	public synchronized void waitForReady() throws InterruptedException {
+	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) {
 	        while (!readyReconnect) {
 	            wait();
@@ -408,7 +422,7 @@
         if (context!=null)
             context.cleanUpSession(null);
         // cleanup zlib decoder for new VNCServer
-        if (isRoot())
+        if (isTreeManager())
             inflater = new Inflater();
     }
 
@@ -515,7 +529,7 @@
         LinkedList<ByteBuffer> bufs = new LinkedList<ByteBuffer>();
         ByteBuffer header = multicastqueue.allocate(16);
         ByteBuffer serial = multicastqueue.allocate(8);
-        if (!isRoot()) {
+        if (!isTreeManager()) {
             reader.readBytes(serial.array(),0,8);
             serial.limit(8);
         }
@@ -640,7 +654,7 @@
         // after connecting VNC server, rfb send SEND_INIT_DATA command and wakes me up if necessary 
     	reconnecting = true;
     	if (reconnectingId!=0) {
-    	    waitForReady();
+    	    waitForVNCConnection();
     	}
     }
 
@@ -654,7 +668,7 @@
     	    treeManager.getList().getFirst().setPort(getAcceptPort());
     	}
         startTreeVncCommandListener();
-    	if(isRoot() && firstTime) {
+    	if(isTreeManager() && firstTime) {
     		getCast = new TreeRootFinderListener(v);
     		Thread thread = new Thread(getCast, "tree-root-find-listener");
     		thread.start();