How many client sockets bind to a ServerSocket ?  
Author Message
hchmoon





PostPosted: 2005-10-7 3:02:00 Top

java-programmer, How many client sockets bind to a ServerSocket ? Hi,
I'm Hee-Chul Moon from South Korea.

I am developing multi-file(about 100~10000 files) sending/receiving
system in Java.

I wonder how many client sockets can bind to a ServerSocket.

In my architect, a Server daemon can listen to several ports. However,
the port resource is so expensive that I want to optimize the number of
port opened.

please, let me know the general knowledge or the method to decide how
many workers are allowed to bind.

 
Gordon Beaton





PostPosted: 2005-10-7 15:29:00 Top

java-programmer >> How many client sockets bind to a ServerSocket ? On 6 Oct 2005 12:01:59 -0700, email***@***.com wrote:
> I am developing multi-file(about 100~10000 files) sending/receiving
> system in Java.
>
> I wonder how many client sockets can bind to a ServerSocket.

The theoretical limit is the number of IP addresses that can connect
multiplied with the number of client port numbers. The number
approaches 2^48.

In practice your system will run out of other resources long before
that, for example the number of descriptors your process can open, or
how much memory you have to handle the connections, etc.

> In my architect, a Server daemon can listen to several ports.
> However, the port resource is so expensive that I want to optimize
> the number of port opened.

You only need one.

/gordon

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
 
Steve W. Jackson





PostPosted: 2005-10-8 0:40:00 Top

java-programmer >> How many client sockets bind to a ServerSocket ? In article <434623c3$email***@***.com>, Gordon Beaton <email***@***.com>
wrote:

> On 6 Oct 2005 12:01:59 -0700, email***@***.com wrote:
> > I am developing multi-file(about 100~10000 files) sending/receiving
> > system in Java.
> >
> > I wonder how many client sockets can bind to a ServerSocket.
>
> The theoretical limit is the number of IP addresses that can connect
> multiplied with the number of client port numbers. The number
> approaches 2^48.
>
> In practice your system will run out of other resources long before
> that, for example the number of descriptors your process can open, or
> how much memory you have to handle the connections, etc.
>
> > In my architect, a Server daemon can listen to several ports.
> > However, the port resource is so expensive that I want to optimize
> > the number of port opened.
>
> You only need one.
>
> /gordon

I'm in the process of designing an application now that will use a
ServerSocket to accept connections. As a result, I've been reviewing a
tutorial I saw once before. I think it makes what Gordon has said
(about only needing one port) clear in a simple fashion. A visit to
<http://java.sun.com/docs/books/tutorial/networking/sockets/index.html>
will be time well spent.

= Steve =
--
Steve W. Jackson
Montgomery, Alabama
 
 
Gordon Beaton





PostPosted: 2005-10-8 3:56:00 Top

java-programmer >> How many client sockets bind to a ServerSocket ? On Fri, 07 Oct 2005 11:39:42 -0500, Steve W. Jackson wrote:
> I'm in the process of designing an application now that will use a
> ServerSocket to accept connections. As a result, I've been reviewing
> a tutorial I saw once before. I think it makes what Gordon has said
> (about only needing one port) clear in a simple fashion. A visit to
><http://java.sun.com/docs/books/tutorial/networking/sockets/index.html>
> will be time well spent.

Just be aware that the description (under "what is a socket") of how
the connection is accepted by the server is completely wrong.

The server does *not* get "a new socket bound to a different port" for
the incoming connection. The original ServerSocket and all connected
client Sockets use the same port number at the server end. Each client
continues to communicate with the same port it originally connected
to.

/gordon

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
 
 
Roedy Green





PostPosted: 2005-10-8 5:21:00 Top

java-programmer >> How many client sockets bind to a ServerSocket ? On 6 Oct 2005 12:01:59 -0700, email***@***.com wrote or quoted :

>please, let me know the general knowledge or the method to decide how
>many workers are allowed to bind.

I think you will run out of RAM first. Also consider that TCP/IP at
the low level is likely handled by the OS, so the limit would be its'
not Java's. For Windows, look in the C++ Windows API for a limit.

Since Java runs on such a wide variety of hardware, it would not make
sense for there to be a fixed Java limit. Your server app decides it
by how many times it calls accept.



--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
 
 
Roedy Green





PostPosted: 2005-10-8 5:24:00 Top

java-programmer >> How many client sockets bind to a ServerSocket ? On 7 Oct 2005 09:29:07 +0200, Gordon Beaton <email***@***.com> wrote or
quoted :

>> In my architect, a Server daemon can listen to several ports.
>> However, the port resource is so expensive that I want to optimize
>> the number of port opened.
>
>You only need one.

read my little essay on how TCP/IP works to understand why it is
possible to double up on ip input ports and why you don't need unique
ip return ports for each connection.

See http://mindprod.com/jgloss/tcpip.html


--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
 
 
Roedy Green





PostPosted: 2005-10-8 5:26:00 Top

java-programmer >> How many client sockets bind to a ServerSocket ? On 7 Oct 2005 21:56:21 +0200, Gordon Beaton <email***@***.com> wrote or
quoted :

>Each client
>continues to communicate with the same port it originally connected
>to.

You don't use ip port numbers to keep track of your clients, you use
their return ip/return ip port pair. Neither of which is assigned
from your pool of resources.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
 
 
Steve W. Jackson





PostPosted: 2005-10-12 0:26:00 Top

java-programmer >> How many client sockets bind to a ServerSocket ? In article <4346d2e5$email***@***.com>, Gordon Beaton <email***@***.com>
wrote:

> On Fri, 07 Oct 2005 11:39:42 -0500, Steve W. Jackson wrote:
> > I'm in the process of designing an application now that will use a
> > ServerSocket to accept connections. As a result, I've been reviewing
> > a tutorial I saw once before. I think it makes what Gordon has said
> > (about only needing one port) clear in a simple fashion. A visit to
> ><http://java.sun.com/docs/books/tutorial/networking/sockets/index.html>
> > will be time well spent.
>
> Just be aware that the description (under "what is a socket") of how
> the connection is accepted by the server is completely wrong.
>
> The server does *not* get "a new socket bound to a different port" for
> the incoming connection. The original ServerSocket and all connected
> client Sockets use the same port number at the server end. Each client
> continues to communicate with the same port it originally connected
> to.
>
> /gordon

Strange, that. I was doing some test code to ensure I could properly
accept connections and use serialized objects for communication, and my
test code showed exactly this same thing. Nevertheless, the sample is
useful as a starter for working with sockets.

= Steve =
--
Steve W. Jackson
Montgomery, Alabama