Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

java rmi connection exception

Posted on 2010-11-28
20
Medium Priority
?
515 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses

721 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