Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

rmi binding ?

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

618 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