From 1b84bcdc8c8ba120c2ba24db6a465f4bea49f805 Mon Sep 17 00:00:00 2001 From: Brian Hinz Date: Sun, 30 Oct 2011 16:08:05 +0000 Subject: [PATCH] re: bug #3429667. adds support for reverse connection mode git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4744 3789f03b-4d11-0410-bbf8-ca57d06f2519 --- java/com/tigervnc/vncviewer/VncViewer.java | 39 ++++++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/java/com/tigervnc/vncviewer/VncViewer.java b/java/com/tigervnc/vncviewer/VncViewer.java index e5cf1579..604069c4 100644 --- a/java/com/tigervnc/vncviewer/VncViewer.java +++ b/java/com/tigervnc/vncviewer/VncViewer.java @@ -32,6 +32,10 @@ import java.awt.Color; import java.awt.Graphics; import java.awt.Image; import java.io.InputStream; +import java.io.IOException; +import java.lang.Character; +import java.net.ServerSocket; +import java.net.Socket; import java.util.jar.Attributes; import java.util.jar.Manifest; import javax.swing.*; @@ -108,8 +112,8 @@ public class VncViewer extends java.applet.Applet implements Runnable public static void usage() { String usage = ("\nusage: vncviewer [options/parameters] "+ "[host:displayNum] [options/parameters]\n"+ - //" vncviewer [options/parameters] -listen [port] "+ - //"[options/parameters]\n"+ + " vncviewer [options/parameters] -listen [port] "+ + "[options/parameters]\n"+ "\n"+ "Options:\n"+ " -log configure logging level\n"+ @@ -188,8 +192,34 @@ public class VncViewer extends java.applet.Applet implements Runnable public void run() { CConn cc = null; + Socket sock = null; + if (listenMode.getValue()) { + int port = 5500; + ServerSocket listener = null; + if (vncServerName.getValue() != null && + Character.isDigit(vncServerName.getValue().charAt(0))) + port = Integer.parseInt(vncServerName.getValue()); + + try { + listener = new ServerSocket(port); + } catch (IOException e) { + System.out.println("Could not listen on port: "+port); + System.exit(-1); + } + + vlog.info("Listening on port "+port); + + try { + sock = listener.accept(); + listener.close(); + } catch (IOException e) { + System.out.println("Accept failed: "+port); + System.exit(-1); + } + + } try { - cc = new CConn(this, null, vncServerName.getValue(), false); + cc = new CConn(this, sock, vncServerName.getValue(), false); while (true) cc.processMsg(); } catch (EndOfStream e) { @@ -255,6 +285,9 @@ public class VncViewer extends java.applet.Applet implements Runnable = new StringParameter("DesktopSize", "Reconfigure desktop size on the server on "+ "connect (if possible)", ""); + BoolParameter listenMode + = new BoolParameter("listen", "Listen for connections from VNC servers", + false); StringParameter scalingFactor = new StringParameter("ScalingFactor", "Reduce or enlarge the remote desktop image. "+ -- 2.39.5