File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes NX: (Contractors) Do you guys hard code the port number? 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 "NX: (Contractors) Do you guys hard code the port number?" Watch "NX: (Contractors) Do you guys hard code the port number?" New topic
Author

NX: (Contractors) Do you guys hard code the port number?

Nitti Lin
Ranch Hand

Joined: May 15, 2003
Posts: 39
When I am writting the userguide, a problem came across to my mind. Do I need to allow user to setup the port number for server to listen? I currently, hard-coded it, but not sure if it's appropriate.
My question is, what if another running program is listening to the same port number, my server won't be able to run.
Will Sun's examiners be picky on this?
Thanks,
Nitti
[ June 04, 2003: Message edited by: Nitti Lin ]

SCJP, SCWCD, SCJD, (SCEA, MCSD.net)
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

I myself took the default port and was fine. Since I took the defualt there was no hard coding of it.
Now if you specifically hard code a port then I would suggest a different solution.
In design it is best to not hard code things. Especially location type items like drive letters, file locations, and port numbers. Because what if they want to change them, then the code will have to change, recompiled and in most cases reloaded on the clients machine. Not fun.
If you are providing a screen for the user to enter the server location, then I suggest also giving them the option to enter the port number, you could have this field default to the default port number, and then only when they want a different port number would they enter that in.
Good Luck
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Max Habibi
town drunk
( and author)
Sheriff

Joined: Jun 27, 2002
Posts: 4118
When I did the new assignment, I allowed the client to pick the port number, though I has a default in place.
M


Java Regular Expressions
Nitti Lin
Ranch Hand

Joined: May 15, 2003
Posts: 39
Thank you very much guys, I think that I will add the function that allow user to setup the server and port number.
Thanks,
Nitti
Nitti Lin
Ranch Hand

Joined: May 15, 2003
Posts: 39
Guys,
Now, I allow user sets up the host and port number from GUI client in the standalone mode, but... how about the database filename and path? I do have function that allow the user to setup the database filename and path in the standalone mode, but I didn't save it to the properties file.
Should I save it to properties file, and when in the network mode, server would access the database filename and path that user set up?
If yes, my question is, if a remote user starts the GUI client in the standalone mode and sets the database filename and path to another remote location. The database filename and path might become something like W:\\db-2x3.db. When the server starts, W: maybe make no sense to the machine that the server resides on. How do you guys take care of this?
Do you guys save the database filename and path to the properties file and let server to use that database filename and path?
Thanks, and sorry about that I might think too much and confuse you guys.
Nitti
[ June 05, 2003: Message edited by: Nitti Lin ]
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

", I allow user sets up the host and port number from GUI client in the standalone mode"

There is no server in standalone mode/local mode. So there is no host or port number.
Yes I think you should save teh database location in the properties file, it is just a nice feature.
When a user is in standalone mode, they don't have to change to remote mode in the middle of running.
Also when the server runs you will probably need a gui to set the location for the server.
Now if the client is to be in remote mode, then setting the database location should be disabled. Since it makes no sense to set a database file location when your are just getting a remote class from the the server. At this point the client doesn't need to know or care about the database file location.
Does this make sense?
Mark
Nitti Lin
Ranch Hand

Joined: May 15, 2003
Posts: 39
Hi Mark,
Thank you very much of your reply.
1) Do you always pops up a GUI dialog for user to set the host and port number when start the server?
2) When start the client in standalone mode, do we need to make sure that user runs this mode on the same machine where the server is at? If yes, is that OK that I use existance of suncertify.properties file to check if it's on the same machine?
3) The reasons that I worry so much is I don't know if Sun will fail me because I didn't take all the detail things into consideration. Are they very picky?
Thanks,
Nitti
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
1) Do you always pops up a GUI dialog for user to set the host and port number when start the server?
I think we have to. The user has to be able to configure things, yet they can't use command-line options and we can't require them to edit a properties file. So our only remaining option seems to be to provide a GUI. However I think this GUI should be set up so that it defaults to the values you used last time (saved in the rops file) and so most of the time you just hit an "OK" button and the server starts using those values.
2) When start the client in standalone mode, do we need to make sure that user runs this mode on the same machine where the server is at?
No, in standalone mode we don't care if there's a server running somewhere or not - whether it's on this machine or somewhere else. We're using our own Data source, and no server (no networking code at all). We might care if there were a server running on our machine and using the same db file we are (from standalone mode) - that could be bad. But we have been told we can assume no other programs are accessing the file at the same time. So we don't care about any other programs/servers in standalone mode.


"I'm not back." - Bill Harding, Twister
Nitti Lin
Ranch Hand

Joined: May 15, 2003
Posts: 39
Hi Jim,
Thanks for replying.
OK, now, I know what confused me. According to this project, is there only one copy of runme.jar existed on the example company's network? Any user who wants to run a client, he has to execute that one and only one copy of runme.jar. If it's right, my concern will not be the case.
Thanks,
Nitti
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NX: (Contractors) Do you guys hard code the port number?