Maximum number of sockets?

Maximum number of sockets?

Post by Chung Ch » Thu, 11 Nov 1999 04:00:00



I'm writing a multi-threaded Java program that continuously opens a socket
connection to a server (SMTP server).  However, if I have too many threads
going at once, I get a "BindException: Address in use."  It seems like there
is a limit to the number of sockets I can create?  (Is that true?)  And also,
the Java VM is probably not closing the other sockets fast enough.

Has anyone come across this before?

Thanks for any help!

-Chung

 
 
 

Maximum number of sockets?

Post by Mike McCar » Fri, 12 Nov 1999 04:00:00



)
)I'm writing a multi-threaded Java program that continuously opens a socket
)connection to a server (SMTP server).  However, if I have too many threads
)going at once, I get a "BindException: Address in use."  It seems like there
)is a limit to the number of sockets I can create?  (Is that true?)  And also,

Since real computers have only a finite amount of memory, they have
only a finite number of states. Therefore there are only a finite number
of sockets which can be opened at one time.

Mike
--
----
char *p="char *p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
This message made from 100% recycled bits.
I don't speak for Alcatel      <- They make me say that.

 
 
 

Maximum number of sockets?

Post by Timo Nyyss?ne » Fri, 12 Nov 1999 04:00:00


Quote:> I'm writing a multi-threaded Java program that continuously opens a socket
> connection to a server (SMTP server).  However, if I have too many threads
> going at once, I get a "BindException: Address in use."  It seems like there
> is a limit to the number of sockets I can create?  (Is that true?)  And also,
> the Java VM is probably not closing the other sockets fast enough.

Isn't that what you get if you try to bind to a port which is already bound to
another socket. You can do that binding only if use SO_REUSEADDR
option.

Yes, there is limit to the number of sockets but I think you would
encounter that when creating a new socket.

 
 
 

Maximum number of sockets?

Post by Glen Wile » Sun, 14 Nov 1999 04:00:00



> I'm writing a multi-threaded Java program that continuously opens a socket
> connection to a server (SMTP server).  However, if I have too many threads
> going at once, I get a "BindException: Address in use."  It seems like there
> is a limit to the number of sockets I can create?  (Is that true?)  And also,
> the Java VM is probably not closing the other sockets fast enough.

> Has anyone come across this before?

> Thanks for any help!

> -Chung

You may bind exactly 1 socket to a specific address/port.  If you
attempt to bind another socket to the same address/port you will
get the error you mentioned.  The number of sockets that can be
opened is equal to the maximum number of file descriptors
available to the process, under Solaris the soft limit is 64
by default.  This can be changed via setrlimit() in C.

--

Staff Software Engineer
3Com Carrier Systems Group, R&D

"UNIX _IS_ user friendly, its just picky about who its friends are."