RMI exportObject(Remote obj, PORT); createRegistry(PORT);
Asked Answered
P

1

1

I'm wondering can both the

UnicastRemoteObject.exportObject(Remote,portNo) & LocateRegistry.createRegistry(portNo);

porNo be the same?

I test it works but I'm worrid if there is any complication?

Why does exportObject need to specify an object to work? when I use exportObject(Remote obj) it throws an NullPointerException.

Patrology answered 12/8, 2011 at 13:47 Comment(0)
S
2

I'm wondering can both the

UnicastRemoteObject.exportObject(Remote,portNo) &
LocateRegistry.createRegistry(portNo);

portNo be the same?

Yes, unless you are using unequal socket factories, which you aren't. If there is a problem an exception will be thrown.

I test it works but I'm worrid if there is any complication?

Not at all, in fact it's a good idea, saves on listening ports. You can use Registry.REGISTRY_PORT which is reserved at IANA, and should therefore shut down any arguments with netadmins too.

Why does exportObject need to specify an object to work?

Because it is a static method.

when I use exportObject(Remote obj) it throws an StubNotFoundException.

Because you haven't generated a stub. If you are using >= 1.5, you don't need a generated stub, but you do need to specify a port number. If you specify zero you will get a system-allocated port number but if you have already exported a remote object, in this case the Registry, you will share its port, again unless you are using unequal socket factories.

Secretin answered 13/8, 2011 at 1:36 Comment(3)
care to define unequal socket factories? Sorry kind of new with this socket and RMI. I'm using 1.6, I get NullPointException.Patrology
@Patrology a NullPointerException means something has not been initialized. I would suggest debugging that code and trying to figure out what variable was left uninitialized.Baten
@Patrology unequal socket factories are socket factories for which sf1.equals(sf2) returns false, as everywhere else in Java.Secretin

© 2022 - 2024 — McMap. All rights reserved.