0

Hello I am creating guacamole driven application and getting error java.net.ConnectException: Connection refused: connect. I tried the code given in guacamole web application documentation getting java.net.ConnectException: Connection refused: connect error

servlet code

@WebServlet
public class HttpTunnelServletController extends GuacamoleHTTPTunnelServlet {

    private static final long serialVersionUID = 1L;
    public static SimpleGuacamoleTunnel tunnel = null;
    @Override
    protected GuacamoleTunnel doConnect(HttpServletRequest request)
        throws GuacamoleException {

        // Create our configuration
        GuacamoleConfiguration config = new GuacamoleConfiguration();
        config.setProtocol("rdp");
        config.setParameter("hostname", "104.197.255.190:8080/guacamole");
        config.setParameter("port", "3389");
        config.setParameter("password", "guacamole");

        // Connect to guacd - everything is hard-coded here.
       GuacamoleSocket socket = new ConfiguredGuacamoleSocket(
                new InetGuacamoleSocket("localhost", 4822),
                config
        );  
        // Return a new tunnel which uses the connected socket
        return new SimpleGuacamoleTunnel(socket);
    }
}

web page

<div class="col-sm-9 col-md-6 col-lg-8 col-xl-10">
        <span class="border">
            <form action="/GuacamoleHTTPTunnelServletController" >
              <!-- Guacamole -->
        <script type="text/javascript"
            src="guacamole-common-js/all.min.js"></script>

        <!-- Display -->
        <div id="display"></div>




        <!-- Init -->
        <script type="text/javascript"> /* <![CDATA[ */

            // Get display div from document
            var display = document.getElementById("display");

            // Instantiate client, using an HTTP tunnel for communications.
            var guac = new Guacamole.Client(
                new Guacamole.HTTPTunnel("/tunnel")
            );

            // Add client to display div
            display.appendChild(guac.getDisplay().getElement());
            
            // Error handler
            guac.onerror = function(error) {
                alert(error);
            };

            // Connect
            guac.connect();

            // Disconnect on close
            window.onunload = function() {
                guac.disconnect();
            }

        /* ]]> */ </script>  <!-- Guacamole -->
        <script type="text/javascript"
            src="guacamole-common-js/all.min.js"></script>

        <!-- Display -->
        <div id="display"><a href="tunnel">URL</a></div>

        <!-- Init -->
        <script type="text/javascript"> /* <![CDATA[ */

            // Get display div from document
            var display = document.getElementById("display");

            // Instantiate client, using an HTTP tunnel for communications.
            var guac = new Guacamole.Client(
                new Guacamole.HTTPTunnel("tunnel")
            );

            // Add client to display div
            display.appendChild(guac.getDisplay().getElement());
            
            // Error handler
            guac.onerror = function(error) {
                alert(error);
            };

            // Connect
            guac.connect();

            // Disconnect on close
            window.onunload = function() {
                guac.disconnect();
            }

        /* ]]> */ </script>
                
            </form>
        </span>
      
    </div>
  </div>
</div>
  </div>
   <!-- Init -->
        <script type="text/javascript"> /* <![CDATA[ */

            // Mouse
            var mouse = new Guacamole.Mouse(guac.getDisplay().getElement());

            mouse.onmousedown = 
            mouse.onmouseup   =
            mouse.onmousemove = function(mouseState) {
                guac.sendMouseState(mouseState);
            };

            // Keyboard
            var keyboard = new Guacamole.Keyboard(document);

            keyboard.onkeydown = function (keysym) {
                guac.sendKeyEvent(1, keysym);
            };

            keyboard.onkeyup = function (keysym) {
                guac.sendKeyEvent(0, keysym);
            };

        /* ]]> */ </script>

What else configuration need to be done. Thanks in advance

jyotsna
  • 51
  • 9

1 Answers1

1

There is a configuration issue in the Java code. The GuacamoleConfiguration object should have the configuration of the target machine (windows) you are connecting to.

In your case, you are using the RDP protocol, so the hostname should have the address of the Windows machine you want to connect to. The username and password for the target windows machine are mandatory when RDP protocol is used. If you are using a domain user, you should also specify the domain parameter.

I believe the basis of your code is from the Guacamole example. This example explains how to connect to the VNC server, which does not require a username. In general, the basic configuration for connecting to windows should look like this:

    // Create our configuration
    GuacamoleConfiguration config = new GuacamoleConfiguration();
    config.setProtocol("rdp");
    config.setParameter("hostname", "104.197.255.190"); // IP or fqdn of the windows machine, no URL
    config.setParameter("port", "3389");
    config.setParameter("username", "some-windows-user");
    config.setParameter("password", "some-windows-user-password");
    config.setParameter("domain", "windows-domain-if-exists");
mnikolic
  • 572
  • 1
  • 5
  • 9
  • yes I am following guacamole example. I did all the above changes but still getting the error – jyotsna Feb 02 '21 at 06:47
  • ERROR org.apache.guacamole.servlet.GuacamoleHTTPTunnelServlet - HTTP tunnel request failed: java.net.ConnectException: Connection refused: connect – jyotsna Feb 02 '21 at 06:47
  • Can you check with telnet if the target windows server is reachable from the host where guacd is running? You may check with `telnet 104.197.255.190 3389`. – mnikolic Feb 02 '21 at 11:41
  • I am creating simple web application which connect to guacamole server to access virtual machine. I tried the code from guacamole example manual. I am using rdp protocol. My question is that do I need to add more configuration to this code. I am new to this guacamole – jyotsna Feb 02 '21 at 14:14
  • The needed parameters are as written above, except for the "domain." The domain should be added if target windows (or target virtual machine) is within the domain. The error you are receiving makes it look like the target virtual machine is not reachable from the guacamole server. This is why I recommend checking network connectivity with telnet. The ConnectException may also happen if guacd is not running on the guacamole server, so you may check this as well. – mnikolic Feb 02 '21 at 15:52
  • guacd is connected on guacamole server – jyotsna Feb 03 '21 at 06:35
  • To make web application do I need to install guacamole server – jyotsna Feb 03 '21 at 07:20
  • Yes, guacamole server should be installed, both java app under tomcat and guacd as a service. The target windows VM must be reachable from the guacamole server via network, this is why I recommend checking this. – mnikolic Feb 04 '21 at 07:06
  • If I already have guacamole server on other machine can I access that machine – jyotsna Feb 04 '21 at 07:12
  • I want my application to access virtual machine provided by guacamole server – jyotsna Feb 04 '21 at 07:14
  • Your client (browser) connects to the guacamole server. The guacamole server connects to the virtual machine and forwards requests to the client. So, it is mandatory that guacamole server can connect to the target virtual machine via network. The error message you are receiving indicates that there may be network issues between guacamole server and virtual machine. I would recommend checking the connectivity as described above. – mnikolic Feb 04 '21 at 07:50
  • the virtual machine is connected with guacamole server – jyotsna Feb 04 '21 at 07:52
  • @mnikonic the guacamole server, guacd are installed on one maching and creating web application on another machine. In guacamoleConfiguration giving credential for machine I am trying to access and GuacamoleSocket giving credential for guacd. Is there any dummy virtual machine to check connection?? because when I an trying to check connection on telnet it is not showing any connection – jyotsna Mar 01 '21 at 07:51