?
Solved

rmi binding ?

Posted on 2002-03-16
4
Medium Priority
?
378 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses
Course of the Month14 days, 1 hour left to enroll

800 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