Java Server Socket & C++ Client Socket

Java Server Socket & C++ Client Socket

Post by rajeshks9 » Sun, 30 May 2004 14:16:10


Hi,
We have a socket server app in Java and the client application in C++.

When we try to connect 60 clients simultaneously from C++ using
threads, only 55-56 connections are successfull, rest are not
connected(Connection refused error).

For one connection everything works fine. In server side each
connection is handled in seperate thread.

Is there anything else to be done?

The server code is as follows.
public class SocketServer
{
public static void main(String args[])
{

ServerSocket Server = null;
Socket clientSocket = null;

try
{
Server = new ServerSocket(7999,60);
}
catch (IOException e)
{
System.out.println(e);
}

try
{
while (true)
{
clientSocket = Server.accept();
SocketThread objThread = new SocketThread(clientSocket);
objThread.start();
}
}
catch (Exception e)
{
System.out.println(e);
}
finally
{

try
{
Server.close();
}
catch (IOException e)
{
System.out.println(e);
}
}

}
}
 
 
 

Java Server Socket & C++ Client Socket

Post by Gordon Bea » Sun, 30 May 2004 18:28:32


You have likely run into an OS-imposed descriptor limit on the server.
You don't say what OS you are using, but on unix you can use ulimit to
check or modify the limit.

I was going to suggest that you look at changing the backlog in the
ServerSocket constructor (in case your clients are connecting too
quickly for the server to handle), but see now that you've already set
it to 60.

I assume that SocketThread closes the Socket when it's done handling
the client?

/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

 
 
 

Java Server Socket & C++ Client Socket

Post by perry ande » Mon, 31 May 2004 00:15:33

just because you have allocated 60 clients doesn't mean that the server
has to connect them all on the first try. connecting sockets is a
dynamic relationship... in otherwords if at first your client does not
succeed, get it to try again after so many seconds...

- perry