Improve company productivity with a Business Account.Sign Up

x
?
Solved

java rmi connection exception

Posted on 2010-11-28
20
Medium Priority
?
531 Views
Last Modified: 2012-08-13
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

0
Comment
Question by:oggiemc
  • 10
  • 6
  • 3
  • +1
20 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 34225575
Make sure the service is running at the right address and port
0
 
LVL 16

Expert Comment

by:Valeri
ID: 34225592
Also make sure that you are not behind a firewall. You have to bypass the proxy in this case.
0
 

Author Comment

by:oggiemc
ID: 34225777
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)

0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
LVL 86

Expert Comment

by:CEHJ
ID: 34225894
>>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
0
 

Author Comment

by:oggiemc
ID: 34225976
cehj, not too sure what you mean..The  registry is running on port 1099
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 34226023
Assuming Windows, please post the output of
netstat -n -p tcp

Open in new window

0
 

Author Comment

by:oggiemc
ID: 34226051
please see attached file
netstat.docx
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 34226113
That shows rmi running on a quite different address
0
 

Author Comment

by:oggiemc
ID: 34226169
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.
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 1500 total points
ID: 34226184
>>java.rmi.ConnectException: Connection refused to host: 195.162.2.1.; nested exception is:

You are apparently trying to connect to a particular address (above). That's a different address to the one shown in netstat. I suggest you use the one shown in netstat instead
0
 

Author Comment

by:oggiemc
ID: 34226239
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
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 34226252
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
0
 

Author Comment

by:oggiemc
ID: 34226336
yes its the same output as before..im confused because ive ran other RMI apps with no problem..Any ideas?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 34226516
It's possibly a server configuration issue
0
 
LVL 16

Expert Comment

by:Valeri
ID: 34226521
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!
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 1500 total points
ID: 34226538
If you don't know what the server is doing and why, you should probably turn on logging at the server
0
 
LVL 16

Expert Comment

by:Valeri
ID: 34226566
Could you please post the output of
tracert 195.162.2.1
0
 
LVL 92

Assisted Solution

by:objects
objects earned 500 total points
ID: 34226931
check your security manage and policy is correct
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 1500 total points
ID: 34226942
Try binding the server to address "localhost" with the same port as you're using currently
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 34342476
:)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
A discussion about automated testing of Web Applications utilizing Selenium, along with illustrated configuration steps for the Jenkins open source tool.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

595 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question