Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Vito Chiofalo
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vito,
Welcome to JavaRanch!
Looks like you forgot to launch the rmiregistry server.
 
Vito Chiofalo
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm. You know that the rmiregistry needs to have the stub files on its CLASSPATH, right?
 
Vito Chiofalo
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic