Solved

rmi binding ?

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
array11 challenge 16 51
array220 challenge 8 46
mapBully challenge 6 89
VB Script to add site to Java Exception List 4 13
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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 one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

705 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now