aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes naming is it OS specific Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "naming is it OS specific" Watch "naming is it OS specific" New topic
Author

naming is it OS specific

ravi janap
Ranch Hand

Joined: Nov 04, 2000
Posts: 389
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


SCJP, SCJD, SCWCD, SCBCD, SCEA
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937

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 ]
ravi janap
Ranch Hand

Joined: Nov 04, 2000
Posts: 389
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
 
wood burning stoves
 
subject: naming is it OS specific