4 Replies Latest reply on Mar 2, 2006 3:58 AM by 843793

    Connection refused to localhost;

    843793
      Hello, this is my first rmi program and I'm having a bit of a problem. when i start rmiregistry and then run this server program I get an error;

      C:\Program Files (x86)\Java\jdk1.5.0_06\bin>java cscie160.hw5.Server
      Main Try Block Failed
      java.rmi.ConnectException: Connection refused to host: localhost; nested exception is:
      java.net.ConnectException: Connection refused: connect
      at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:574)
      at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:185)
      at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:171)
      at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:306)
      at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
      at cscie160.hw5.Server.main(Server.java:38)
      Caused by: 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:507)
      at java.net.Socket.connect(Socket.java:457)
      at java.net.Socket.<init>(Socket.java:365)
      at java.net.Socket.<init>(Socket.java:178)
      at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:22)
      at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:128)
      at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:569)
      ... 5 more
      main exiting




      This is the Code for Server.class which I am trying to run;

      /**
      * digitalaspect
      * */




      import java.rmi.registry.*;

      public class Server {
           /**
           *
           * @exception exception class objects are caught and the stack is printed
           * */
           public static void main(String argv[]) {
                try {
                     ATMFactoryImpl atmf = new ATMFactoryImpl();
                     int port = 3090;
                     String host = "localhost";
                     String name = "ATMFactory";
                          
                     
                     Registry ry = LocateRegistry.getRegistry(host, port);
                     if(ry == null) {
                     System.out.println("getRegistry returned null");
                     System.exit(1);
                     }
                     else{
                          System.out.println("Registry retrieved successfully");
                     }
           
                     try {
                     ry.bind(name, atmf);
                     } catch (Exception e) {
                          System.out.println("Exception caught in registry.bind command");
                          e.printStackTrace();
                     }
                     

                } catch (Exception e) {
                     System.out.println("Main Try Block Failed");
                     e.printStackTrace(); }
                System.out.println("Server Main now exiting");
                System.exit(0);
           }                                   // end of main


      }                                        // end of class