Java Server Socket & C++ Client Socket

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rajesh

    Java Server Socket & C++ Client Socket

    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(Conne ction 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(79 99,60);
    }
    catch (IOException e)
    {
    System.out.prin tln(e);
    }

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

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

    }
    }
  • Gordon Beaton

    #2
    Re: Java Server Socket & C++ Client Socket

    On 28 May 2004 22:16:10 -0700, Rajesh wrote:[color=blue]
    > 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(Conne ction 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?[/color]

    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

    Comment

    • perry anderson

      #3
      Re: Java Server Socket & C++ Client Socket

      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:[color=blue]
      > 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(Conne ction 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(79 99,60);
      > }
      > catch (IOException e)
      > {
      > System.out.prin tln(e);
      > }
      >
      > try
      > {
      > while (true)
      > {
      > clientSocket = Server.accept() ;
      > SocketThread objThread = new SocketThread(cl ientSocket);
      > objThread.start ();
      > }
      > }
      > catch (Exception e)
      > {
      > System.out.prin tln(e);
      > }
      > finally
      > {
      >
      > try
      > {
      > Server.close();
      > }
      > catch (IOException e)
      > {
      > System.out.prin tln(e);
      > }
      > }
      >
      > }
      > }[/color]

      Comment

      Working...