Solved

RMI Stub question...

Posted on 2004-08-05
10
392 Views
Last Modified: 2006-11-17
i'm trying to transfer a stub object to allow it to be invoked on a different machine.

when i do so, the stub object no longer contains a remoteRef? it is now null?

i.e. before the transfer it returns remote ref IP = xxx.xxx.xxx.xxx + port
      after transfer remote ref = null?

any help....
0
Comment
Question by:maxol
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 11727803
it seems somewhere you are wrong
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 11727813
can u post some code snippet so that experts understand

Best Regards
Sudhakar Chavali
0
 

Author Comment

by:maxol
ID: 11728030
RMI object exported is called 'myServer'

RemoteStub rs = RemoteObject.toStub(myServer);

System.out.println(rs.toString())    gives "RemoteStub [ref: 111.111.111.111 ObjID:0] ... okay

after i send it over an ObjectOutputStream and recast it as a stub the

System.out.println(rs.toString())    gives "RemoteStub [ref: null] ... bad, no reference now

??
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 1

Expert Comment

by:wolfc
ID: 11728150
Which version JDK?
0
 

Author Comment

by:maxol
ID: 11728226
jdk1.4.2_01
0
 
LVL 35

Expert Comment

by:girionis
ID: 11728441
Can you make sure it is serializable and the data you want to transfer can also be serialized?
0
 
LVL 7

Expert Comment

by:bvanderveen
ID: 11729186
You need to make  sure the remote interface the stub is implementing is also on the other machine's classpath.
0
 
LVL 1

Accepted Solution

by:
wolfc earned 500 total points
ID: 11734279
Using http://java.sun.com/j2se/1.4.2/docs/guide/rmi/getstart.doc.html as a base.

Added the following to HelloImpl:
      RemoteStub rs = (RemoteStub) RemoteObject.toStub(obj);
      
      System.out.println("rs = " + rs);
      
      ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("hello.ref"));
      out.writeObject(rs);
      out.flush();
      out.close();
                  
Created:
package examples.hello;

import java.io.FileInputStream;
import java.io.ObjectInputStream;

public class HelloFile{
    public static void main(String args[]) {
        try {
              ObjectInputStream in = new ObjectInputStream(new FileInputStream("hello.ref"));
              Object rs = in.readObject();
              in.close();
              
              System.out.println("rs = " + rs);
              Hello obj = (Hello) rs;
              System.out.println(obj.sayHello());
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("HelloFile exception: " + e.getMessage());
        }
    }
}

Got the following on Windows XP using JDK 1.4.2_03:
rs = examples.hello.HelloImpl_Stub[RemoteStub [ref: [endpoint:[192.168.1.7:1441](local),objID:[0]]]]
HelloServer bound in registry
Saying hello to 192.168.1.1

With on Debian Woody Linux 2.4.18 using JRE 1.4.1_05:
carlo@ogre:~/tmp/TestRMI$ java -cp . examples.hello.HelloFile
rs = examples.hello.HelloImpl_Stub[RemoteStub [ref: [endpoint:[192.168.1.7:1441](remote),objID:[1bab50a:fe33b6565b:-8000, 0]]]]
Hello World!

And the same running HelloFile on Windows.

What am I doing right? :-)
0
 

Author Comment

by:maxol
ID: 11734317
you beauty!

i was casting it as a stub when it should have been a remote object on the client side!

i thank you!
0
 
LVL 1

Expert Comment

by:wolfc
ID: 11734596
You're welcome. :-)
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
split53 challenge 7 99
tomcat not starting 6 48
Problem to Alipay 10 24
Crystal Reports Licensing Questions 4 13
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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 …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

832 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