How many client sockets bind to a ServerSocket ?

H

hchmoon

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.
 
G

Gordon Beaton

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
 
S

Steve W. Jackson

Gordon Beaton <[email protected]> said:
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.


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 =
 
G

Gordon Beaton

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
 
R

Roedy Green

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.
 
R

Roedy Green

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.
 
S

Steve W. Jackson

Gordon Beaton <[email protected]> said:
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 =
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top