Fix regression that omitted support for client redirect.

Also, delay showing DesktopWindow until first valid rect has been
recieved.  This allows for a ClientRedirect to take place before
any data rects have been received.
diff --git a/java/com/tigervnc/rfb/CMsgReader.java b/java/com/tigervnc/rfb/CMsgReader.java
index e7b4deb..e9cad89 100644
--- a/java/com/tigervnc/rfb/CMsgReader.java
+++ b/java/com/tigervnc/rfb/CMsgReader.java
@@ -104,6 +104,10 @@
       case Encodings.pseudoEncodingExtendedDesktopSize:
         readExtendedDesktopSize(x, y, w, h);
         break;
+      case Encodings.pseudoEncodingClientRedirect:
+        nUpdateRectsLeft = 0;
+        readClientRedirect(x, y, w, h);
+        return;
       default:
         readRect(new Rect(x, y, x+w, y+h), encoding);
         break;
@@ -259,6 +263,18 @@
     handler.setExtendedDesktopSize(x, y, w, h, layout);
   }
 
+  protected void readClientRedirect(int x, int y, int w, int h)
+  {
+    int port = is.readU16();
+    String host = is.readString();
+    String x509subject = is.readString();
+
+    if (x != 0 || y != 0 || w != 0 || h != 0)
+      vlog.error("Ignoring ClientRedirect rect with non-zero position/size");
+    else
+      handler.clientRedirect(port, host, x509subject);
+  }
+
   public int[] getImageBuf(int required) { return getImageBuf(required, 0, 0); }
 
   public int[] getImageBuf(int required, int requested, int nPixels)
diff --git a/java/com/tigervnc/vncviewer/CConn.java b/java/com/tigervnc/vncviewer/CConn.java
index 8a2303b..128867b 100644
--- a/java/com/tigervnc/vncviewer/CConn.java
+++ b/java/com/tigervnc/vncviewer/CConn.java
@@ -326,6 +326,8 @@
       setServerPort(port);
       sock.inStream().setBlockCallback(this);
       setStreams(sock.inStream(), sock.outStream());
+      if (desktop != null)
+        desktop.dispose();
       initialiseProtocol();
     } catch (java.lang.Exception e) {
       throw new Exception(e.getMessage());
diff --git a/java/com/tigervnc/vncviewer/DesktopWindow.java b/java/com/tigervnc/vncviewer/DesktopWindow.java
index e76a015..187fbad 100644
--- a/java/com/tigervnc/vncviewer/DesktopWindow.java
+++ b/java/com/tigervnc/vncviewer/DesktopWindow.java
@@ -151,21 +151,6 @@
       }
     });
 
-    pack();
-    if (embed.getValue()) {
-      scroll.setHorizontalScrollBarPolicy(HORIZONTAL_SCROLLBAR_AS_NEEDED);
-      scroll.setVerticalScrollBarPolicy(VERTICAL_SCROLLBAR_AS_NEEDED);
-      VncViewer.setupEmbeddedFrame(scroll);
-    } else {
-      if (fullScreen.getValue())
-        fullscreen_on();
-      else
-        setVisible(true);
-
-      if (maximize.getValue())
-        setExtendedState(JFrame.MAXIMIZED_BOTH);
-    }
-
   }
 
   // Remove resize listener in order to prevent recursion when resizing
@@ -227,25 +212,40 @@
     setTitle(name);
   }
 
-	// Copy the areas of the framebuffer that have been changed (damaged)
-	// to the displayed window.
+  // Copy the areas of the framebuffer that have been changed (damaged)
+  // to the displayed window.
 
-	public void updateWindow()
-	{
-	  if (firstUpdate) {
-	    if (cc.cp.supportsSetDesktopSize && !desktopSize.getValue().equals("")) {
-	      // Hack: Wait until we're in the proper mode and position until
-	      // resizing things, otherwise we might send the wrong thing.
-	      if (delayedFullscreen)
-	        delayedDesktopSize = true;
-	      else
-	        handleDesktopSize();
-	    }
-	    firstUpdate = false;
-	  }
+  public void updateWindow()
+  {
+    if (firstUpdate) {
+      pack();
+      if (embed.getValue()) {
+        scroll.setHorizontalScrollBarPolicy(HORIZONTAL_SCROLLBAR_AS_NEEDED);
+        scroll.setVerticalScrollBarPolicy(VERTICAL_SCROLLBAR_AS_NEEDED);
+        VncViewer.setupEmbeddedFrame(scroll);
+      } else {
+        if (fullScreen.getValue())
+          fullscreen_on();
+        else
+          setVisible(true);
 
-	  viewport.updateWindow();
-	}
+        if (maximize.getValue())
+          setExtendedState(JFrame.MAXIMIZED_BOTH);
+      }
+
+      if (cc.cp.supportsSetDesktopSize && !desktopSize.getValue().equals("")) {
+        // Hack: Wait until we're in the proper mode and position until
+        // resizing things, otherwise we might send the wrong thing.
+        if (delayedFullscreen)
+          delayedDesktopSize = true;
+        else
+          handleDesktopSize();
+      }
+      firstUpdate = false;
+    }
+
+    viewport.updateWindow();
+  }
 
   public void resizeFramebuffer(int new_w, int new_h)
   {