title: XmlRpcException: Failed to read server's response: Connection refused: connect
body: <p>I have XML-RPC server, which i believe is working fine. I can connect to server using telnet, and using web browser too, address is (dracek:8080) dracek=name of computer.
  When i try connect using my client i get this error:</p>
  
  <p>org.apache.xmlrpc.XmlRpcException: Failed to read server's response: Connection
  refused: connect</p>
  
  <p>Server should log "Client connected.", but there is not any reaction.</p>
  
  <p>Server code:</p>
  
  <p>public class Main {</p>
  
  <pre><code>private static int port = 8080;
  private static InetAddress ipAddress = null;
  
  public static void main(String[] args) {
  
      try
      {
          ipAddress = InetAddress.getLocalHost(); 
      }
      catch (UnknownHostException e)
      {
          System.out.println("UnknownHostException");
          System.exit(0);
      }      
  
      System.out.println("Starting server.");
  
      try {        
  
          WebServer webServer = new WebServer(port, ipAddress); 
  
          // get XML-RPC Server
          XmlRpcServer xmlRpcServer = webServer.getXmlRpcServer();
          PropertyHandlerMapping phm = new PropertyHandlerMapping();
          phm.addHandler("DBClass", DBClass.class);
  
          // mapping
          xmlRpcServer.setHandlerMapping(phm);
  
          // configuration
          XmlRpcServerConfigImpl serverConfig = (XmlRpcServerConfigImpl) xmlRpcServer
                  .getConfig();
          serverConfig.setEnabledForExceptions(true); 
          serverConfig.setEnabledForExtensions(true);
          serverConfig.setContentLengthOptional(false); 
  
          // start server
          webServer.start();            
  
      }
      catch (Exception e)
      {
          System.out.println(e.getMessage());
      }
      System.out.println("Server succesfully started. IP:" + ipAddress + " Port:" + port + ".");
  
  }
  </code></pre>
  
  <p>DBClass:</p>
  
  <pre><code>    public void testConnection(){
      System.out.println("Client connected.");
  }
  </code></pre>
  
  <p>Client code:</p>
  
  <pre><code>private static InetAddress ipAddress = null;
  private static int port = 8080;
  private static String confFile = "";
  private static XmlRpcClientConfigImpl config;
  
  public static void main(String[] args) {
      System.out.println("Starting client.");
  
      if (args.length == 3) {
          try {
              ipAddress = InetAddress.getByName(args[0]);
              port = Integer.parseInt(args[1]);
              confFile = args[2];
          }
          catch (NumberFormatException e) {
      System.out.println("Port number is not valid!");
      System.exit(0);
          }
          catch (UnknownHostException e)
          {
              System.out.println("UnknownHostException");
              System.exit(0);
          }             
  }
      else
      {
          System.out.println("Some parameter is missing!");
          System.out.println("Valid parameters are: IP(0) Port(1) Config_file_name(2).");
      }
  
  
  Client.config = new XmlRpcClientConfigImpl();
  try
      {
          Client.config.setServerURL(new URL("http://" + ipAddress + ":" + port)); // nastaveni   
      }
      catch(MalformedURLException me)
      {
          System.out.println("Server URL is not valid!");
          System.exit(0);        
      }
  
  Client.config.setEnabledForExtensions(true);
  Client.config.setEnabledForExceptions(true);
  
  Client.config.setConnectionTimeout(60 * 1000); 
  Client.config.setReplyTimeout(60 * 1000); 
  
  XmlRpcClient client = new XmlRpcClient();
  
  client.setTransportFactory(new XmlRpcSunHttpTransportFactory(client));
  
  client.setConfig(Client.config);
  
  System.out.println("Connnected to " + ipAddress + " : " + port + ".");
  
      Tools tools = new Tools(client);
  
      tools.testConnection();
      }
  </code></pre>
  
  <p>Tools Class:</p>
  
  <pre><code>public class Tools {
  
  private XmlRpcClient client;
  
  public Tools(XmlRpcClient client)
  {
      this.client = client;
  }
  public void testConnection() {
  
  Object[] params = new Object[] {};
  
      try
      {   
          this.client.execute("DBClass.testConnection", params);
      }
      catch (XmlRpcException e)
      {
          System.out.println("Error occured when testing connection!"); 
          System.out.println(e.toString());
      }            
  }     
  </code></pre>
  
  <p>I run client using command:</p>
  
  <p>java -Djava.security.policy=..\Client\src\client\Client.policy -jar ..\Client\dist\Client.jar dracek 8080 ..\data\commands.txt</p>
  
  <p>thanks with best Regards</p>