Solved

rmi binding ?

Posted on 2002-03-16
4
375 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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

688 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