Link to home
Start Free TrialLog in
Avatar of oggiemc
oggiemcFlag for Ireland

asked on

java rmi connection exception

Hi all,

Im getting the following connection exception when i try to run a java RMI client class:

java.rmi.ConnectException: Connection refused to host: 195.162.2.1.; nested exception is:
      java.net.ConnectException: Connection refused: connect
      at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:601)
      at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:198)
      at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:184)
      at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:110)
      at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:178)
      at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:132)
      at $Proxy0.getNextCashierNum(Unknown Source)
      at AuctionClient.<init>(AuctionClient.java:36)
      at AuctionClient.main(AuctionClient.java:77)
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: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 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:595)

Ive included the client class..
Can someone help me out here please

Thanks in advance
// imports for GUI
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;

// imports for RMI
import java.rmi.Naming; 
import java.rmi.RemoteException; 
import java.net.MalformedURLException; 
import java.rmi.NotBoundException; 

public class AuctionClient extends JFrame 
{
 private DataControl dc; 

 private JTabbedPane jTabbedPane = null;
 private JPanel jContentPane = null;

 private Container container;
 private FlowLayout layout;

 private int cashierNumber;


 public AuctionClient (DataControl dcParm) 
  {
   super ("Auction Interface");

   // set up data
   dc = dcParm;
  // dc.readBidders ("Bidders.csv");
  // dc.readItems ("Items.csv");

   try{
   cashierNumber = dc.getNextCashierNum();
   } catch (Exception e) 
   { e.printStackTrace(); }

   layout = new FlowLayout();

   // get content pane and set its layout
   container = getContentPane();
   container.setLayout( layout );  

   jTabbedPane = new JTabbedPane();
   //jTabbedPane.add("Users", getJUsersPane());
   //jTabbedPane.add("Items", getJItemsPane());	
   jTabbedPane.add("Bids", new BidPanel(dc));
   jTabbedPane.add("Check Out", new CheckOutPanel(dc, cashierNumber));

   container.add (jTabbedPane);

   setSize( 700, 500 );
   setVisible( true );

  }



 public static void main( String args[] )
   { 

    try 
     { 
      String hostName;
      InputStreamReader is = 
        new InputStreamReader(System.in);
      BufferedReader br = new BufferedReader(is);
      System.out.println(
        "Enter the RMIRegistry host namer:");
      hostName = br.readLine();

      DataControl dc = (DataControl) Naming.lookup(
                 "rmi://" + hostName + "/AuctionServer"); 

      AuctionClient application = new AuctionClient(dc);
      application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

     } 
    catch (MalformedURLException murle) 
     { 
            System.out.println(); 
            System.out.println( "MalformedURLException"); 
            System.out.println(murle); 
     } 
    catch (RemoteException re)
     { 
            System.out.println(); 
            System.out.println( "RemoteException"); 
            System.out.println(re); 
     } 
    catch (NotBoundException nbe)
     { 
            System.out.println(); 
            System.out.println( "NotBoundException"); 
            System.out.println(nbe); 
     } 
    catch (Exception e)
     { 
            System.out.println(); 
            System.out.println( "Exception"); 
            System.out.println(e); 
     } 
   }

}

Open in new window

Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Make sure the service is running at the right address and port
Also make sure that you are not behind a firewall. You have to bypass the proxy in this case.
Avatar of oggiemc

ASKER

Valeri, I havent had problems running servlets with apache tomcat so should this be an issue?

cehj, the ip address is my local machine and im using the RMI default port (1099)

>>cehj, the ip address is my local machine and im using the RMI default port (1099)

That may be so. That's a different question to whether it's running
Avatar of oggiemc

ASKER

cehj, not too sure what you mean..The  registry is running on port 1099
Assuming Windows, please post the output of
netstat -n -p tcp

Open in new window

Avatar of oggiemc

ASKER

please see attached file
netstat.docx
That shows rmi running on a quite different address
Avatar of oggiemc

ASKER

Ok, Im new to this.What am i suppose to be looking at here? From what i can see, under local address i see my IP address followed by port number 1099 and under foreign address, my IP followed by port number 55526..What is the foreign address referencing / what am i suppose to be looking for? Any explanation would be much appreciated.
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of oggiemc

ASKER

Ok, i changed the address and still getting the same error:


java.rmi.ConnectException Connection refused to host: 192.168.1.1; nested exception is:
      java.net.ConnectException: Connection refused: connect
      at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:601)
      at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:198)
      at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:184)
      at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:110)
      at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:178)
      at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:132)
      at $Proxy0.getNextCashierNum(Unknown Source)
      at AuctionClient.<init>(AuctionClient.java:36)
      at AuctionClient.main(AuctionClient.java:77)
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: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 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:595)
      ... 8 more
If netstat is still giving the same output as before (check) then it looks like the server is not configured to allow your host to connect
Avatar of oggiemc

ASKER

yes its the same output as before..im confused because ive ran other RMI apps with no problem..Any ideas?
It's possibly a server configuration issue
I'm not so familiar with that, but... could it be some NAT between these two IP adresses?
Probably it's better to ask your sysadmin.
>> Valeri, I havent had problems running servlets with apache tomcat so should this be an issue?
servlets operates on http port, RMI registry uses another port, so it could be an firewall issue!
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Could you please post the output of
tracert 195.162.2.1
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
:)