• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Sun's RMI tutorial - Help !

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I'm trying to teach myself RMI from Sun's tutorial, I'm using Windows 98 (without a network or webserver , in case that makes a difference) and am running into problems with getting the Calculator example to work, first I'll list a couple of the problems that I've overcome, which may be of help to others:-
I found that I needed to set CLASSPATH in autoexec.bat inorder to get the files to compile, I've currently got the following line in my autoexec.bat
SET CLASSPATH=.;C:\jdk1.3.0_02\jre\classes;C:\javatutorials\rmi\example;C:\java\rmi;
(Sorry if these seems trivial - but it took me a little while to figure out)
Next I found that I was getting the following exception after starting the client :-
C:\javatutorials\rmi\example>java CalculatorClient
client starting
RemoteException
java.rmi.UnknownHostException: Unknown host: remotehost; nested exception is:
java.net.UnknownHostException: remotehost
After searching through the RMI group I found that someone else had had this problem and that remotehost should be replaced by localhost. I'm suprised that the Sun Tutorial has a typing error like this, if thats what it is, surely they must have been alerted to the error by now. Perhaps it isn't an error, but using localhost seemed to improve matters - it now manages to create a Calculator object using Naming.lookup, but I now get the following NoRouteToHostException :-
C:\javatutorials\rmi\example>java CalculatorClient
client starting
client about to call sub
RemoteException
java.rmi.ConnectIOException: Exception creating connection to: 4.0.0.3; nested e
xception is:
java.net.NoRouteToHostException: Host unreachable: connect

I've copied the code (4 java files) below, its pretty much cut and pasted from Sun's Tutorial, with a few System.out.println's so I know where its got to.
I've tried using a permit file as suggested in the "Just Java 2" book, but that doesn't make any difference, and i've got a feeling that that isn't the problem. I did have a firewall (Tiny's personal firewall) running, but I've disabled it, so it isn't due to that. I've also tried running with an open internet connection, with the same results, except that it takes longer to not work (don't know why that should make any difference, but I read somewhere that it might). I'm going to carry on experimenting with different approaches, but I'm really clutching at straws, and have a feeling it could be something really simple that I just don't know about (I know next to nothing about TCP/IP , networking etc.) - any help would be appreciated , in the meantime if I find out a solution I'll post a follow up here
thanks Mike





[ March 31, 2002: Message edited by: Mikey Warren ]
[ March 31, 2002: Message edited by: Mikey Warren ]
 
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mikey
Before you start the server you have to start the "rmiregistry". Then you need to set the port number in CalculatorClient.java - see code:

/Ren�
 
Mikey Warren
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Rene,
I'd taken the :1099 out of the
Calculator c = (Calculator) Naming.lookup("rmi://localhost:1099/CalculatorService");
line because I was running out of things to try, I'd read that that was the default port, so it should work anyway, then forgot to put it back. But I've just tried it again, with your suggested line, and get the same results.
I knew I was meant to run rmiregistry first - I don't get any feedback that its working OK, just the egg timer cursor symbol for a few seconds, then the dos box just sits there, not accepting anymore input, which I presume means the registry is up and running OK.
I've run out of things to try for the moment - I'm going to try the example in "Just Java 2", to see if that has the same problem, I'm wondering if its something to do with my computer not having a network card, so perhaps TCP/IP isn't set up fully - although I've tried "ping localhost", which works OK - so I was hoping that RMI should work using localhost also.
See below for the order I've compiled things in, followed by the starting of the registry :-
C:\javatutorials\rmi\example>javac Calculator.java
C:\javatutorials\rmi\example>javac CalculatorImpl.java
C:\javatutorials\rmi\example>rmic CalculatorImpl
C:\javatutorials\rmi\example>javac CalculatorServer.java
C:\javatutorials\rmi\example>javac CalculatorClient.java
C:\javatutorials\rmi\example>rmiregistry
Then I do the following in another dos box :-
C:\javatutorials\rmi\example>java CalculatorServer
which gives the following output in the dos box, and then also hangs, which I presume means the server is up and running OK:-
Creating calc
Binding service
service bound
In a third dos box I get the following (as before)
C:\javatutorials\rmi\example>java CalculatorClient
client starting
client about to call sub
RemoteException
java.rmi.ConnectIOException: Exception creating connection to: 4.0.0.3; nested e
xception is:
java.net.NoRouteToHostException: Host unreachable: connect
 
Rene Larsen
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
When I run your code I get:

/Ren�
 
Mikey Warren
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Rene,
I think there must be something wrong with my PC's setup - I'll try it at work, on Windows 2000, on Tuesday.
I also tried the example from "Just Java 2", and got a similar result, although it was when the WeatherServer was started (rather than the client).
Mike
[ March 31, 2002: Message edited by: Mikey Warren ]
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

4.0.0.3


If you are using localhost, which is just a name given to your computer, which should always be IP address 127.0.0.1. So when I see 4.0.0.3 I am wondering why?
You could always find out your exact IP address by typing ipconfig. There should be a few numbers given and one that says IP address, you could try to substitute localhost with that exact IP address.
Basically what you are doing here is telling RMI what is the URI/URL or IP address of the machine running the RMIRegistry.
Mark
 
Mikey Warren
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Mark, - with your help I've cracked it.
I didn't know about ipconfig - it was just what I needed. When I used it I got details for three Ethernet Adpaters, one of which was 4.0.0.1. I remembered that I used to have a different modem installed so that explained having two adapters. After a bit of playing about with the network settings I noticed that there was a "Microsoft TV Data Adapter", which I didn't have any idea what it was, but I tried removing it, which resulted in my PC being unable to shutdown normally and me wondering when I last did A backup , I hit the power switch.
On power up I tried running the Calculator example again, and it magically worked - ipconfig now shows two adapters, the ip address for both is "obtained automatically" from my isp, so I've gone back to using "localhost", although forcing the adpaters to have static ip address's, and hardcoding the address into the client and server code also worked (but obviously prevented me from connecting to the internet)

Just to prove it works here's the output from the Client's dos box (its probably a bit pointless, but after two days work I'm quite proud of it):-
C:\javatutorials\rmi\example>ipconfig
Windows 98 IP Configuration
0 Ethernet adapter :
IP Address. . . . . . . . . : 0.0.0.0
Subnet Mask . . . . . . . . : 0.0.0.0
Default Gateway . . . . . . :
1 Ethernet adapter :
IP Address. . . . . . . . . : 0.0.0.0
Subnet Mask . . . . . . . . : 0.0.0.0
Default Gateway . . . . . . :
C:\javatutorials\rmi\example>java CalculatorClient
client starting
client about to call sub
1
9
18
3
C:\javatutorials\rmi\example>
 
reply
    Bookmark Topic Watch Topic
  • New Topic