Solved

rmi binding ?

Posted on 2002-03-16
4
373 Views
Last Modified: 2013-12-29
Hello,

 

 I made my own example to get rmi straight in my head.  The code is below.

On a windows 98 machine I get exceptions like this on the client side:

App exception: HelloAll
java.rmi.NotBoundException: HelloAll
       at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknow
n Source)
       at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
       at sun.rmi.server.UnicastRef.invoke(Unknown Source)
       at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
       at java.rmi.Naming.lookup(Unknown Source)
       at HelloApp.main(HelloApp.java:11)

 

I must be doing something wrong on this line: "Naming.rebind("//localhost/HelloAll", obj);"

The HelloAll is just a share name on the localhost referring to the obj object right?  Or is the share name important?

Here's the code:

//HelloServer.java  the interface
//my attempt at an original rmi EXAMPLE
//16 mar 2002, should output text


import java.rmi.*;

public interface HelloServer extends Remote {
public String outputIt(String str) throws RemoteException;
}

 

////////// end ////////////

//HelloServerImpl

//Implementation

import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;


public class HelloServerImpl extends UnicastRemoteObject
implements HelloServer {

 String helloStr;

 public HelloServerImpl() throws RemoteException {
 super();
 
}

 public String outputIt(String str) throws RemoteException {
 System.out.println(str);
 return str;
}

 public static void main (String argv[]) {
 System.setSecurityManager(new RMISecurityManager());

  try {
  HelloServerImpl obj = new HelloServerImpl ();

   Naming.rebind("//localhost/HelloAll", obj);

   System.out.println("HelloAll bound in registry");

    }
  catch (Exception e) {
   System.out.println("HelloAll eror CAUGHT " + e.getMessage());
   e.printStackTrace();
  }

 }

}

 

///////////////////// end ///////////////////////

// HelloApp.java

// client side

import java.rmi.*;
import java.net.*;

 public class HelloApp {


 public static void main (String argv[] ) {
  String eee = new String();
   try {
   
    HelloServer obj = (HelloServer) Naming.lookup("//localhost/HelloAll");
    eee = obj.outputIt("hello, how are u");

   }
  catch (Exception e) {
   System.out.println("App exception: " + e.getMessage() );
   e.printStackTrace();
  }

  System.out.println(" the string here on the client is " + eee );

 }

}

//////////// end /////////////////

 

Any hints would be much appeciated.

 

thanks,

whatever

0
Comment
Question by:whatever080697
[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
4 Comments
 

Expert Comment

by:maggari
ID: 6873008
First, I hope you are starting the rmiregistry before starting the your server.

The argument to Naming.lookup() and Naming.rebind() should be in the following format:

rmi://<host_name>[:<name_service_port>]/<service_name>

In your case,

rmi://localhost:1099/HelloAll

The port by default is 1099. If you are using the default port, there is no need to mention that.

For a brief information refer to the following page.

http://developer.java.sun.com/developer/onlineTraining/rmi/RMI.html

Good luck
0
 

Author Comment

by:whatever080697
ID: 6874454
Maggari, thanks for the info but I found that if I comment out the System.setSecurityManager(new RMISecurityManager()); line in the HelloServerImpl I get this exception on windows 2000:

"

App exception: error unmarshalling return; nested exception is:
        java.lang.ClassNotFoundException: HelloServerImpl_Stub (no security mana
ger: RMI class loader disabled)
java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
        java.lang.ClassNotFoundException: HelloServerImpl_Stub (no security mana
ger: RMI class loader disabled)
java.lang.ClassNotFoundException: HelloServerImpl_Stub (no security manager: RMI
 class loader disabled)
        at sun.rmi.server.LoaderHandler.loadClass(Unknown Source)
        at sun.rmi.server.LoaderHandler.loadClass(Unknown Source)
        at sun.rmi.server.MarshalInputStream.resolveClass(Unknown Source)
        at java.io.ObjectInputStream.inputClassDescriptor(Unknown Source)
        at java.io.ObjectInputStream.readObject(Unknown Source)
        at java.io.ObjectInputStream.readObject(Unknown Source)
        at java.io.ObjectInputStream.inputObject(Unknown Source)
        at java.io.ObjectInputStream.readObject(Unknown Source)
        at java.io.ObjectInputStream.readObject(Unknown Source)
        at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
        at java.rmi.Naming.lookup(Unknown Source)
        at HelloApp.main(HelloApp.java:11)
 the string here on the client is

"

On a win 98 machine if I comment the setsecuritymanager line out the program works fine.
0
 
LVL 9

Expert Comment

by:Venci75
ID: 7901432
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
PAQ'd and pts refunded
Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Venci75
EE Cleanup Volunteer
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 7962421
Per recommendation, points refunded and question closed.

Netminder
EE Admin
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

726 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