5 Replies Latest reply: Dec 9, 2009 4:01 PM by jschellSomeoneStoleMyAlias RSS

    java.net.ConnectException: Connection refused: connect

    843810
      Code is given below

      /*
      * Created on Oct 30, 2004
      *
      * To change the template for this generated file go to
      * Window>Preferences>Java>Code Generation>Code and Comments
      */
      package com.axsscm.scheduler.job;

      import java.net.*;
      import java.io.*;

      import org.quartz.Job;
      import org.quartz.JobDataMap;
      import org.quartz.JobExecutionContext;
      import org.quartz.JobExecutionException;

      import org.apache.log4j.Logger;

      /**
      * @author guruprasada
      *
      * To change the template for this generated type comment go to
      * Window>Preferences>Java>Code Generation>Code and Comments
      */
      public class SchedulerJob implements Job {
           
           private static final Logger log = Logger.getLogger(SchedulerJob.class);
           private boolean isDebugEnabled = log.isDebugEnabled();
           
           /**
           * <p>
           * Called by the <code>{@link org.quartz.Scheduler}</code> when a <code>{@link org.quartz.Trigger}</code>
           * fires that is associated with the <code>Job</code>.
           * </p>
           *
           * @throws JobExecutionException
           * if there is an exception while executing the job.
           */
           public void execute(JobExecutionContext context)
                throws JobExecutionException
           {
                     if (isDebugEnabled) {
                          log.debug("Entering method SchedulerJob:execute");
                     }
                     
                     JobDataMap dataMap = context.getJobDetail().getJobDataMap();
                     String jobUrl = dataMap.getString("Servlet");
                URL url = null;
                     
                     try
                     {
                     url = new URL(jobUrl);
                     }
                catch(MalformedURLException muEx)
                {
                log.error("Unable to execute Job. MalformedURLException caught in SchedulerJob:execute");
                     throw new JobExecutionException(muEx);
                }
                
                try {  
                     URLConnection ucon = url.openConnection();
                     ucon.connect();
                     BufferedReader in = new BufferedReader(new InputStreamReader(ucon.getInputStream()));
                     String inputLine;
                     in.close();
                     }
                     catch(IOException ex)
                     {
                     ex.printStackTrace();
                     throw new JobExecutionException(ex);
                     }
           
                     if (isDebugEnabled) {
                          log.debug("Entering method SchedulerJob:execute");
                     }
           }

      }


      When this is executed i got tyhe following exception

      java.net.ConnectException: Connection refused: connect
      at java.net.PlainSocketImpl.socketConnect(Native Method)
      at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
      at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
      at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
      at java.net.Socket.connect(Socket.java:516)
      at java.net.Socket.connect(Socket.java:466)
      at sun.net.NetworkClient.doConnect(NetworkClient.java:157)
      at sun.net.www.http.HttpClient.openServer(HttpClient.java:365)
      at sun.net.www.http.HttpClient.openServer(HttpClient.java:477)
      at sun.net.www.http.HttpClient.<init>(HttpClient.java:214)
      at sun.net.www.http.HttpClient.New(HttpClient.java:287)
      at sun.net.www.http.HttpClient.New(HttpClient.java:299)
      at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLC
      onnection.java:795)
      at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConne
      ction.java:747)
      at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection
      .java:672)
      at com.axsscm.scheduler.job.SchedulerJob.execute(SchedulerJob.java:62)
      at org.quartz.core.JobRunShell.run(JobRunShell.java:191)
      at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.j
      ava:516)


      Can any one expect why this error occured
      Plz reply at earliest possible
        • 1. Re: java.net.ConnectException: Connection timed out: connect
          843810
          Sir,
          I am sending mail automatically through javamail.I create a thread that sleep until required time reach.
          But after thread exited i call the method to send mail,but it gives java.net.ConnectException: Connection timed out: connect exception.Can you tell me why it is happening.
          • 2. Re: java.net.ConnectException: Connection refused: connect
            843810
            hi,

            The following error is occoured when i am running my application.

            I/O exception (java.net.ConnectException) caught when processing request: Connection refused

            Please help me where is the problem??


            Thanks in advance
            Neelam
            • 3. Re: java.net.ConnectException: Connection refused: connect
              jschellSomeoneStoleMyAlias
              IT_professional-26 wrote:
              hi,

              The following error is occoured when i am running my application.

              I/O exception (java.net.ConnectException) caught when processing request: Connection refused

              Please help me where is the problem??

              Don't post new questions on old posts.

              One of the following
              - The port is wrong.
              - Firewall is stopping it.
              • 4. Re: java.net.ConnectException: Connection refused: connect
                843810
                ya .... when i do socket connection for my host with specified address checked from whatismyip.com

                i got the same problem .. the connection to host string not found.

                java.net.ConnectException: Connection refused: connect
                at java.net.PlainSocketImpl.socketConnect(Native Method)
                at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
                at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
                at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
                at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
                at java.net.Socket.connect(Socket.java:525)
                at java.net.Socket.connect(Socket.java:475)
                at java.net.Socket.<init>(Socket.java:372)
                at java.net.Socket.<init>(Socket.java:186)
                at client1.main(client1.java:20)


                this is the error occuring for me.


                actually my system ip address is dynamic. i checked for the ip address using whatismyip.com and then using that ip address i made the socket connection program.

                but it compiles well while running it shows the above.

                i m running both the server socket and client socket connections within my system.

                When i use network loopback address 127.0.0.1 it works fine. but when i place my original ip address its not working fine.

                Need help ....

                Thanks in advance
                • 5. Re: java.net.ConnectException: Connection refused: connect
                  jschellSomeoneStoleMyAlias
                  sundar_rajan wrote:
                  ya .... when i do socket connection for my host with specified address checked from whatismyip.com
                  What part of "Don't post new questions on old posts." did you not understand?
                  What part of the previous responses did you not understand?
                  checked from whatismyip.com
                  Which doesn't mean much. If I run that from my home box it gives me an ip which will NEVER allow me to connect to my box.

                  Internet addresses require a public IP which you must control/own. If you do not have that then you can't connect.