RMI exportObject(Remote obj, PORT); createRegistry(PORT);

陌路散爱 提交于 2019-12-06 16:10:49

问题


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:


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.



来源:https://stackoverflow.com/questions/7040986/rmi-exportobjectremote-obj-port-createregistryport

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!