By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,557 Members | 1,184 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,557 IT Pros & Developers. It's quick & easy.

Java Server Socket & C++ Client Socket

P: n/a
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);
}
}

}
}
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On 28 May 2004 22:16:10 -0700, Rajesh wrote:
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?


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
Jul 17 '05 #2

P: n/a
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
Rajesh wrote:
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);
}
}

}
}


Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.