Hi all. In preperation for an exam question I would be gratefull for the following info.
ServerSocket.accept() returns an instance of a new socket.. I got that.. but does it open a new port for every connection?.. if so how does it decide which port to use ? is there a pre defined approach (eg. it just increments the port number and if its free it uses it) if this is so.. are the number of potential simultanious connections limited to the number of free ports?.. I know this is a simple question, i would just like to get it straight..
Originally posted by Alex Joyce: but does it open a new port for every connection?.. if so how does it decide which port to use ?
That's up to the operating system to decide:
These port numbers are generally assigned in a pseudo-random manner from a reserved pool of numbers. I say �pseudo-random� because there is no specific meaning to an ephemeral port number assigned to a process, so a random one could be selected for each client process. However, since it is necessary to reuse the port numbers in this pool over time, many implementations use a set of rules to minimize the chance of confusion due to reuse.