LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-15-2011, 12:24 PM   #1
nag_ramone
LQ Newbie
 
Registered: Apr 2011
Posts: 3

Rep: Reputation: 0
Java RMI on Linux connection problems


Hello everyone!
First of all, sorry about my english, it sucks, I know.

I got a little problem using RMI on a linux server.
This is the stage...

Linux server:
Running CentOS 5.
Java & Javac -version: 1.6.0_24
SSH server running ok on port 22.

Open port 1099 for RMI with system-config-securitylevel-tui Ok. Like 1099:tcp
iptables describes this configuration for por 1099

Code:
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 1099 -j ACCEPT
Data in /etc/hosts file
Code:
192.168.1.67    centos5test
127.0.0.1       centos5test
::1             localhost6.localdomain6 localhost6
Next verification
Code:
#nestat -napt |grep 1099

tcp        0      0 :::1099                     :::*                        LISTEN      4054/java       
tcp        0      0 ::ffff:192.168.1.67:1099    ::ffff:192.168.1.103:53525  ESTABLISHED 4054/java       
tcp        0      0 ::ffff:192.168.1.67:1099    ::ffff:192.168.1.67:51309   ESTABLISHED 4054/java       
tcp        0      0 ::ffff:192.168.1.67:51309   ::ffff:192.168.1.67:1099    ESTABLISHED 4054/java
192.168.1.103 is another machine with W7 OS... It has a RMI monitor.
It looks like conections are established but when I try to do any call to the RMI server, it fails.

When I look for the registry and the remote object with this Java line

Code:
Registry registry = LocateRegistry.getRegistry("192.168.1.67",1099);

Then print registry object to console and get:
RegistryImpl_Stub[UnicastRef [liveRef: [endpoint:[192.168.1.67:1099](remote),objID:[0:0:0, 0]]]]
So the registry EXISTS.
Next step, try to get the remote object, like this.
Code:
DataProvider dp = (DataProvider)registry.lookup(DataProvider.SERVICE_NAME);
Print the dp object to console and I get this:
Proxy[DataProvider,RemoteObjectInvocationHandler[UnicastRef [liveRef: [endpoint:[192.168.1.67:45719](remote),objID:[-e3dd853:12f5977846c:-7fff, 1478379431391312706]]]]]


Okey, it looks like its gonna work! But...
When I call a remote method (this method onlye returns true to the caller)... but never shows up!

Code:
dp.checkService()
After this, I get this error...

Code:
java.rmi.ConnectException: Connection refused to host: 192.168.1.67; nested exception is: 
	java.net.ConnectException: Connection timed out: 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)
There's no timeout set up in any side of the test.


Other stages tested...

Win Server - Win Client (OK)
Win Server - Linux Client ()
Linux Server - Linux Client (OK)
Linux Server - Win Client ()

Any idea??? I newbie using linux and I can't figure out what's the problem...

Thanks u all...
 
Old 04-16-2011, 06:30 AM   #2
thermite_1033
Member
 
Registered: May 2004
Location: Antwerp, Belgium
Distribution: slackware
Posts: 112

Rep: Reputation: 18
try running the server with the system property -Djava.rmi.server.hostname=<server-hostname>
 
Old 04-16-2011, 11:29 PM   #3
nag_ramone
LQ Newbie
 
Registered: Apr 2011
Posts: 3

Original Poster
Rep: Reputation: 0
Yes, I've already done that...

I forgot to put it on the main post, sorry.

I've been using this to start the server...

Code:
#java -Djava.rmi.server.hostname=192.168.1.67 -jar dp-server.jar --disable-gui &

--disable-gui is just an option for the provider
Btw... it's still with problems... thnks for the tip!

Last edited by nag_ramone; 04-16-2011 at 11:30 PM.
 
Old 04-17-2011, 05:47 AM   #4
thermite_1033
Member
 
Registered: May 2004
Location: Antwerp, Belgium
Distribution: slackware
Posts: 112

Rep: Reputation: 18
I sligthly still remember something about java not reading the hosts file correctly when it tries to look for hostname of localhost.

so modifying the hosts file by adding the localhost entries (which were missing from your hosts file)

Code:
192.168.1.67    localhost centos5test
127.0.0.1       localhost centos5test
::1             localhost6.localdomain6 localhost6
 
Old 04-18-2011, 11:40 AM   #5
nag_ramone
LQ Newbie
 
Registered: Apr 2011
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks for your help.
I've been looking for this problem in google and I found that Java RMI needs to open 2 diferent ports, 1099 is default port for rmiregistry and random one for the remote object.

I've forced my application to use port 1099 for rmiregistry and 1100 for the remote object.
I've also open this new port on my firewall and after that, everything runs fine...


I hope this may help to other people with a similar problem.

How to force the remote object in our application to run on a determinated port.

Code:
Registry registry = java.rmi.registry.LocateRegistry.createRegistry(1099);
DataProvider engine = new DataProviderEngine();
DataProvider engineStub = (DataProvider) UnicastRemoteObject.exportObject(engine, 1100);
registry = LocateRegistry.getRegistry();
registry.rebind(DataProvider.SERVICE_NAME, engineStub);
Thanks u all.
 
Old 05-06-2011, 11:36 AM   #6
tops20
LQ Newbie
 
Registered: Jul 2008
Location: Los Angeles, California
Posts: 1

Rep: Reputation: 0
I had the same problem and found this thread using a Google search. The solution in the 4-18-11 post did not work for me. It generated an error that translated to "Object already exported."

Digging deeper, I realized that the problem was in how the object was being exported. The solution used a static method in the UnicastRemoteObject. My code as subclassing UnicastRemoteObject. The constructor was doing the export so calling the static method was unnecessary and resulted in an exception.

The UnicastRemoteObject class has a constructor that takes an integer argument for the port to use. My implementation class now has a constructor that takes an integer. This is passed to the UnicastRemoteObject constructor (super(int_value)) and the firewall problem goes away.

While the solution posted earlier did not work in my case, it did point me in the right direction. Thanks to all who posted here.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
java rmi +access denied trscookie Programming 4 05-16-2006 05:43 PM
Java RMI Connection Problem mtest Programming 7 09-01-2005 02:43 PM
Java RMI ClassCastException sherryanee Programming 2 10-19-2004 05:25 PM
Java RMI in Linux?? hiteshmaisheri Linux - Software 0 04-20-2004 10:30 AM
About Java RMI poeta_boy Programming 4 01-27-2004 02:18 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration