This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi In RMI while binding the name to RMI registry if we enter the name as String name = "rmi://" + ip + ":" + port + "/Server"; Does it by any chance tied to windows environment? What I mean is that the seperator "/", is it tied to windows environment ? If the answer is Yes, we need to pick up the OS specific separator in case we aim to make our application run on multiple OS. Similarly, when we look up this name from registry. I do something like this. String svr = "rmi://" + ip + ":" + port + "/Server"; return (RemoteDataIntf) Naming.lookup(svr); Have I hardcoded the seperator to a particular OS i.e windows ? Thanks Ravi
Well I think in the case of rmi:// like http:// is the same accross platforms. I have the /s hardcoded and they work in both Windows and UNIX. Now if you are trying to get a file, then you can use the os.seperator "Constant" to get the correct slash in those cases. Mark
String name = "rmi://" + ip + ":" + port + "/Server"; Does it by any chance tied to windows environment?
No, it is cross-platform because it is a URL-formatted String, so you are OK. Here is more from Sun's Javadoc for Naming class: "The Naming class provides methods for storing and obtaining references to remote objects in the remote object registry. The Naming class's methods take, as one of their arguments, a name that is a URL formatted java.lang.String of the form: //host: port/name where host is the host (remote or local) where the registry is located, port is the port number on which the registry accepts calls, and where name is a simple string uninterpreted by the registry. Both host and port are optional. If host is omitted, the host defaults to the local host. If port is omitted, then the port defaults to 1099, the "well-known" port that RMI's registry, rmiregistry, uses." Incidentally, you are using "ip" as a variable name to specify the host, does it mean you expect it to be an IP address? What happens if your user specifies "FatBrain" and the server name, -- will your program still work? Eugene. [ February 19, 2003: Message edited by: Eugene Kononov ]
Joined: Nov 04, 2000
Hi Eugene I am not sure how the program would behave if given such a input. However I tested the application in an intranet environment with the rmi server running on linux and the ip address of the machine being 192.168.0.6 . I binded the server name rmi://192:168.0.6:2000/Server to the registry On the client side ( Windows ) I looked up the name rmi://192:168.0.6:2000/Server and got the server reference. I also tested the application with both the client and server running on linux and it worked satisfactorily. Thanks Ravi