Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > RMI without the rmiregistry

Reply
Thread Tools

RMI without the rmiregistry

 
 
JP Martin
Guest
Posts: n/a
 
      10-05-2004
All,

I am trying to use RMI to get to java programs to talk to each other
in a simpler way than sending messages over sockets. In my case, the
two programs already use sockets for some of their communication, so
it seems that I should not have to bother with the RMI Registry... or
should I?

Here's my client code:

public void hit() throws Exception {
Socket socket = new Socket("localhost",9943);
ObjectInputStream in = new
ObjectInputStream(socket.getInputStream());
Object o = in.readObject();
System.out.println("Received: "+o);
((HitMe)o).hit();
}

public static void main(String argv[]) throws Exception {
new TestRMIClient().hit();
}

The HitMe interface extends Remote and only has the hit() method. I
wrote an implementation for it that just displays a message.

The server does mostly the same thing, sends the object to the
client. The relevant lines are:

// in the constructor; MyHitMe extends UnicastRemoteObject
// and implements the HitMe interface.
hitme = new MyHitMe();

// in response to a connection from a client
out.writeObject( hitme );


Here's the output I get from the client:

Received: MyHitMe[RemoteStub [ref:
[endpoint:[<my-ip-here>:46846](local),objID:[0]]]]
I'm hit!

This shows that the passed object was (as I was expecting) not of the
implementation type (MyHitMe) but instead of the stub type generated
by
rmic (RemoteStub). Now, I'm expecting the stub to forward method calls
to the server process, so then the "I'm hit" message should be
displayed
at the server.

But it's not. The message gets displayed on the client, and I don't
understand why.


Does anyone here understand what's happening? Will I have to use the
RMI Registry even though I have no need for discovery since my app
already runs at a well-known location on a well-known port?

Thanks in advance,
JP
(please reply to the thread since I don't check that email often)
 
Reply With Quote
 
 
 
 
Esmond Pitt
Guest
Posts: n/a
 
      10-06-2004
ObjectOutputStream.writeObject() doesn't replace a remote object by its
stub, only RMI does this, so you are serializing the object itself and
so it acts at the wrong peer. Try out.writeObject(
RemoteObject.toStub(hitme) ); You may then run into codebase issues if
you haven't deployed the stubs, which you can solve by wrapping the stub
in a MarshalledObject. Easier to use the registry, on the whole.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How does jconsole find MBeans without rmiregistry running? John Java 0 09-21-2005 12:38 PM
rmiregistry woes jonck Java 6 01-24-2005 12:37 AM
Monitoring the rmiregistry silarri Java 3 01-04-2005 12:51 PM
Running Rmiregistry as service, problem on logofff. Arun Goel Java 0 11-12-2003 06:41 PM
RMI with rmiregistry on remote host Rob Dempster Java 1 10-08-2003 04:18 PM



Advertisments