File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Distributed Java and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Distributed Java
Bookmark ""java.net.ConnectException: Connection refused" got in Linux (RedHat 9)" Watch ""java.net.ConnectException: Connection refused" got in Linux (RedHat 9)" New topic
Author

"java.net.ConnectException: Connection refused" got in Linux (RedHat 9)

Vito Chiofalo
Greenhorn

Joined: Dec 04, 2003
Posts: 6
Hi, I have a simple RMI application (server and client). I run the rmiregistry from the prompt and after I run the script launching the server. Well, it perfectly works on WIN2K OS, but in Linux (RedHat 9) it doesn't. I get the following exception:
java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is:
java.net.ConnectException: Connection refused
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:567)
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:313)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at java.rmi.Naming.rebind(Naming.java:160)
at TestMainServer.main(TestMainServer.java:32)
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
at java.net.Socket.connect(Socket.java:434)
at java.net.Socket.connect(Socket.java:384)
at java.net.Socket.<init>(Socket.java:291)
at java.net.Socket.<init>(Socket.java:119)
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:562)
... 6 more

Could some teach me on what is happening?
Many thanks, Vito
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Hi Vito,
Welcome to JavaRanch!
Looks like you forgot to launch the rmiregistry server.


[Jess in Action][AskingGoodQuestions]
Vito Chiofalo
Greenhorn

Joined: Dec 04, 2003
Posts: 6
Hi Ernest,
maybe my message was not clear enough !
I've run the rmiregistry <port#> from a terminal.
After I've run my server.
I hope it clarifies a bit my problem.
Many thanks,
Vito
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Well, let's see. It's certainly possible to use iptables (firewall software) to block access to specific ports on a machine, even from on that same machine, but the symptom would be a timeout, not a "connection refused."
What port are you running rmiregistry on? Call it "N". If N < 1024, it won't work on UNIX; you have to be root to bind to a low-numbered port. But there, the symptom would be that the rmiregistry wouldn't run.
After you run rmiregistry, can you telnet to it? If you type "telnet localhost N", what happens?
I know this sounds dumb, but stranger things have happened: are you sure both terminal windows are connected to the same host
Vito Chiofalo
Greenhorn

Joined: Dec 04, 2003
Posts: 6
I'm working with the port 2055.
I'm on console, so I'm working with the same machine ... Neverthless, I know this big mistakes could happen ;-)
Then I run the rmiregistry 2055 in a terminal.
From another terminal I run the telnet localhost 2055 and I get the following:
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
So i think the rmiregistry seems to work.
Many thanks for your support,
Vito
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Are you sure the server knows about the same non-standard rmiregistry port -- i.e., is it used in the "rmi://" URL based to the "rebind" call?
Vito Chiofalo
Greenhorn

Joined: Dec 04, 2003
Posts: 6
Yes ... the rmiregistry and the "connection string" link to the same address and port.
I've tried in another way without success ... just to investigate:
I've run the rmiregistry in the Linux machine (on the port 2055).
I've tried to register the server to that registry getting the following exception:
java.rmi.UnmarshalException: Error unmarshaling return header; nested exception is:
java.net.SocketException: Connection reset
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:203)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:350)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at java.rmi.Naming.rebind(Naming.java:160)
at TestMainServer.main(TestMainServer.java:34)
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:168)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:183)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:222)
at java.io.BufferedInputStream.read(BufferedInputStream.java:277)
at java.io.ObjectInputStream$PeekInputStream.read(ObjectInputStream.java:2150)
at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2163)
at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2631)
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:734)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:253)
at sun.rmi.server.MarshalInputStream.<init>(MarshalInputStream.java:110)
at sun.rmi.transport.ConnectionInputStream.<init>(ConnectionInputStream.java:38)
at sun.rmi.transport.StreamRemoteCall.getInputStream(StreamRemoteCall.java:111)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:197)
... 4 more
Does it suggest something more ?
Thanks,
Vito
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Wait, I don't understand how this is different from what you were doing before. You're running the rmiregistry, then the server, both on the same machine. Right? What were you doing before?
Vito Chiofalo
Greenhorn

Joined: Dec 04, 2003
Posts: 6
Sorry Ernest ... I miss something ...
I've run the rmiregistry on the Linux machine and after I've tried to register the RMI server object remotely from a WIN2K machine.
In this case I get the second exception.
Tks,
Vito
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Hmmm. You know that the rmiregistry needs to have the stub files on its CLASSPATH, right?
Vito Chiofalo
Greenhorn

Joined: Dec 04, 2003
Posts: 6
Yes Ernest ... Both _Stub and _Skel classes are in CLASSPATH environmente variable of the user I'm working with.
It perfectly works on the WIN2K machine ...
Don't you know some security setting I've to check in my Linux machine ?
In the Linux machine, if I run the rmiregistry internally to the JVM with the following code:
LocateRegistry.createRegistry(rmiPort);
(where rmiPort is an integer const valued 2055) it works fine: the server is properly registerd to the registry and the clien is able to contact it and to call the "remote" method.
Vito
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Are you sure the rmiregistry you're running is the Sun one, and not part of one of the open-source pseudo-Java implementations (Kaffe, gcj) which come with Redhat? In my experience, these things never do anything but malfunction and crash (with apologies in advance to the hordes of folks who will swear otherwise.)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: "java.net.ConnectException: Connection refused" got in Linux (RedHat 9)