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 Port Puzzle ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Port Puzzle ?" Watch "Port Puzzle ?" New topic
Author

Port Puzzle ?

Gurpreet Saini
Ranch Hand

Joined: Jun 09, 2002
Posts: 295
Hi reader,
I had read lot of posts and had found that clients are using port numbers to connect with server. My questions is if client's are supposing that server is running on say port X then dont you think that this supposition theory is wrong. Why should client needs to know the port of server on which it is running ?. Don't you think this is not feasible in practical applications. I mean to say even assignment graders will also not be happy to see this. In case of IP address / host name it may be acceptable. What you think guys ?.
Thank you,
friso dejonge
Ranch Hand

Joined: Jul 11, 2002
Posts: 162
I am not sure what you are aiming at. Standardly when no port is supplied for rmi and rmiregistry portnumber 1099 is used. For this project i do not think it is required to have that ever changed. (I recall messages from people who made a server without any changeable portnumbers and they made a perfect 100 percent score on the server)
However in practice an administrator may not want the rmi/registry to run on 1099 because something else is running on that port already. Therefore it may be wise to have it changeable, both on client and server.
Again, i dont think this will gain extra points, but it is a nice feature.


swimming certificate (A & B), shoelaces diploma, and some useless java ones.
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937

Why should client needs to know the port of server on which it is running ?. Don't you think this is not feasible in practical applications. I mean to say even assignment graders will also not be happy to see this.

It is perfectly acceptable to require that the client knows on which port the server is running. You will not lose points for this.
Eugene.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
IMHO (Unix biased) the client should only know the service which is mapped to a port number outside the application.
Better still the client should use a additional level of indirection to get the service too.
This allows an adminstrator to fiddle around with port numbers without clobbering the application.
-Barry


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Gurpreet,
You don't have to supply a port parameter, but as a practical matter it is probably better. RMI is infamous for not playing well with firewalls, so the network administrator may need the RMI server to run on a non-standard port for security reasons (or because there is already a service running on 1099).
Hope this helps,
Michael Morris


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Gurpreet Saini
Ranch Hand

Joined: Jun 09, 2002
Posts: 295
Hi morris and company,
So, on which port shall I bind my ServerSocket class ?. And tell me once the port has been binded for server. That same port will be used by client . Isn't it ?.
Thank you,
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Gurpreet,
In my case, I had an optional port parameter so that if it were omitted, the server would be bound to the default port 1099.
Are you using Sockets instead of RMI? If you're using RMI there is no need to ever create a ServerSocket. Also, if you are using Sockets, the port is entirely up to you, after all for Sockets you have to establish your own communication protocol. Just make sure it is above port 1024, since ports below that require super user permission.
Hope this helps,
Michael Morris
[ August 07, 2002: Message edited by: Michael Morris ]
Gurpreet Saini
Ranch Hand

Joined: Jun 09, 2002
Posts: 295
Hi morris,
Are you using Sockets instead of RMI?

Isn't we have to use Sockets and RMI ?. I dont know specification says anything about that you have to use RMI or Sockets. Or do the specifications say ?. I was thinking to implement both because my assignment says you have to have handle multiple clients. And moreover Mark suggested that you are supposed to implement Sockets in order to handle multiple clients. This thing can be implemented by RMI itself but I dont think that it will be acceptable. I dont know what you want to say.
Thank you,
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Gurpreet,
The instructions say you must use either RMI or object serialization over Sockets. If you use RMI, it will take care of creating all the Sockets for you so there should be no need to create any Sockets or ServerSockets.
Hope this helps,
Michael Morris
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937

The instructions say you must use either RMI or object serialization over Sockets.

I think it's the use of the word "over" that some non-English speakers misinterpret. I am not sure if it is in FAQ yet, but if it is not, perhaps Mark could make it more explicit in FAQ that the 2 choices are:
1. RMI
2. Object Serialization using Sockets
Eugene.
Gurpreet Saini
Ranch Hand

Joined: Jun 09, 2002
Posts: 295
Hi morris,
Before this thing I was about to do both the things ie Sockets and RMI but you awared me to use any one of them. So, I will go for RMI only. Could you please also respond to my other post
Thank you,
Gurpreet Saini
Ranch Hand

Joined: Jun 09, 2002
Posts: 295
Hi morris,
As you had said there is choice in between RMI and Sockets. So, I would be using RMI only. But the the thing is I want to allot a single user a thread. Such that if there is any problem with that thread it will not interrupt other clients. But if I use RMI then how can I implement this thing. Please connote me this thing technically.
Thank you,
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Gurpreet,
If you use a connection factory, you don't have to worry about clients clobbering each other. RMI itself will then take care of threading for you. If you're not familiar with the Factory Pattern, then you should take some time learning it before proceeding with your server design.
Hope this helps,
Michael Morris
Gurpreet Saini
Ranch Hand

Joined: Jun 09, 2002
Posts: 295
Hi morris,
If you're not familiar with the Factory Pattern, then you should take some time learning it before proceeding with your server design.

Can you give me an idea over this FACTORY. Please tell is this factory a user defined manufacturing unit or it is jdk utility factory.
Thank you,
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Gurpreet,
I gave a brief overview of a connection factory on this thread:
Connection Factory Description
Hope this helps,
Michael Morris
Gurpreet Saini
Ranch Hand

Joined: Jun 09, 2002
Posts: 295
Hi morris,
I read your link. Morris what I understand from the spec is that they need only record number to be locked such that no two client threads / requests enter in running stage. You must have handled the case which I had just mentioned. Please do tell me that is lock / unlock methods will use synchronized keyword with them or not. I feel they will NOT. But stll I want your opinion ?.
Thank you,
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Gurpreet,
Well I did synchronize both lock and unlock, but it is perfectly acceptable to synchronize on whatever data structure (Map, Set, etc.) contains the currently locked records. It increases performance to synchronize on the data structure, but it is riskier to do so.
Hope this helps
Michael Morris
Gurpreet Saini
Ranch Hand

Joined: Jun 09, 2002
Posts: 295
Hi morris,
I do not debate why did you used sunchronized on you lock / unlock method. But Morris the thing is what would be the real significance would be left of lock and unlock. I fancy they had provided these methods at the cost of synchronization. By applying synchronization simply, means deploying of MUTEX and MUTEX is nothing but invitation to systems CPU's to monitor lock and unlocks.
I might be using synchronization on lock and unlock. But only after thought. Ah ! could you tell me any class which implements FIFO.
Thank you,

Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Gurpreet,
Well I think you finally stumped me. As far as I know, there is no built-in FIFO data structure in the Collection API, but creating one should be straight forward. Just use a List (ArrayList would probably be the easiest to work with) for your underlying structure and create your own push and pop methods in the class.
Out of curiosity though, how do you plan to make the FIFO thread-safe without synchronization?
One further point, the instructions say that complicating your design for the sake of perfomance may cost you points. So just keep that in mind.
Hope this helps,
Michael Morris
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Port Puzzle ?