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.

1 Answer 1

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.

3
  • care to define unequal socket factories? Sorry kind of new with this socket and RMI. I'm using 1.6, I get NullPointException.
    – seesee
    Aug 13, 2011 at 2:55
  • @seesee a NullPointerException means something has not been initialized. I would suggest debugging that code and trying to figure out what variable was left uninitialized. Aug 13, 2011 at 3:18
  • @seesee unequal socket factories are socket factories for which sf1.equals(sf2) returns false, as everywhere else in Java.
    – user207421
    Aug 13, 2011 at 10:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.