Max. no. of Socket (TCP) Connection in Java

Dear All,
Made a java based chat program for a business application. Having serious problem, when the number of users exceeds 28 all the client sockets connected to the server throws java.io.EOFException.
Tested the server in couple of machines, when the socket connections touches 29 its not responding. Is there any limitation or setup to be done to use maximum no. of socket connection in JVM or in Operating System ?
Please help me out. Its really very very urgent
Server running in a PC machine loaded with Windows 2003 Server
Rgds
VenQuet
Edited by: venquett on Apr 8, 2008 3:54 AM

all the client sockets connected to the server throws java.io.EOFExceptionThat indicates that the server has closed them all. Are you sure that's the exception you get?
You should be able to get hundreds of connections. The limit is not imposed by Java but by your operating system, or possibly the server.

Similar Messages

  • How to control tcp connection with java tcp socket programing ??

    Hi,
    I am connecting a server as using java socket programming.
    When server close the connection (socket object) as using close() method ,
    I can not detect this and My program continue sending data as if there is a connection with server.
    How to catch the closing connection ( socket ) with java socket programming.
    My Client program is as following :
    import java.io.PrintWriter;
    import java.net.Socket;
    public class client
      public client()
       * @param args
      public static void main(String[] args)
        Socket socket=null;
        PrintWriter pw=null;
        try
                          socket = new Socket("localhost",5555);
                          pw = new PrintWriter(socket.getOutputStream(),true);
                          int i=0;
                          while (true)
                            i++;
                            pw.println(i+". message is being send.");
                            Thread.sleep(5000);
        } catch (Exception ex)
                          ex.printStackTrace();
        } finally
                          try
                            if(pw!=null)pw.close();
                            if(socket!=null)socket.close();
                          } catch (Exception ex)
                            ex.printStackTrace();
                          } finally
    }

    I changed the code as following. But I couldn't catch the EOFException when I read from the socket. How can I catch this exception ?
    import java.io.BufferedReader;
    import java.io.EOFException;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.PrintWriter;
    import java.net.Socket;
    import java.net.UnknownHostException;
    public class client
      public client()
       * @param args
      public static void main(String[] args)
        Socket socket=null;
        PrintWriter pw=null;
        BufferedReader bufIn=null;
        InputStreamReader inRead=null;
        InputStream in=null;
        try
                          socket = new Socket("localhost",5555);
                          in = socket.getInputStream();
                          inRead = new InputStreamReader(in);
                          bufIn = new BufferedReader(inRead);
                          pw = new PrintWriter(socket.getOutputStream(),true);
                          int i=0;
                          while (true)
                            i++;
                            try
                              bufIn.readLine();
                              pw.println(i+". message is being send.");
                              System.out.println(i+". message has been send");
                            } catch (Exception ex2)
                              System.out.println(ex2.toString());
                              System.out.println(i+". message could not be send");
                            } finally
                            Thread.sleep(5000);
        } catch (EOFException ex)
                          ex.printStackTrace();
        } catch (InterruptedException ex)
                          ex.printStackTrace();
        } catch (IOException ex)
                          ex.printStackTrace();
        } finally
                          try
                            if(pw!=null)pw.close();
                            if(socket!=null)socket.close();
                          } catch (Exception ex)
                            ex.printStackTrace();
                          } finally
    }

  • Socket (TCP) connection to proprietary port

    Anyone ever tried to create a tcp socket connection to another machine on a non-reserved port from a java app loaded into Oracle 8.1.5? I have been able to do so with other sites/ports but am unable to create a socket with one particular site. I am baffled because the exact same code I am using connects perfectly if run from a non-Oracle JVM on the OS. Anyone have experienced this before?
    Baffled,
    Jason.

    There are no problems using sockets from Oracle 8i JVM.
    As you are using 8.1.5 you may need to garnt JAVAUSERPRIV or
    JAVASYSPRIV roles to the users.
    JAVAUSERPRIV privileges:
    - open a TCP/IP socket
    - read or write from a file using UTL_FILE_DIR
    JAVASYSPRIV privileges:
    - all the privileges associated with JAVAUSERPRIV
    - create a subprocess
    - listen on a specific network port
    - set the socket factory
    - set the stream handler
    - read or write from any file
    If your problem is specific please feel free to update this thread with more details.
    Regards
    Ravi

  • OSB using socket Transport ,how to keep a TCP connection open

    hi my firends,
    i met a problem , our project need build an OSB to control a socket service which is able to transfer a big data file (maybe a voice file,*.wav),and the client program will play the voice file on live.
    So my solution is that : keep a socket (tcp) connection open,client listen port and makes date play.
    but i can't make the OSB socket transport alway open,it will timeout after a few second if have none date received.
    how could i deal with it ... pls let me konw if you have any idea...i will wait you on line
    thanks guys

    Hi,
    I'm not sure if that's achievable using OSB, and even if it was, I don't think OSB was designed having this type of application in mind...
    I understand that you need a media streaming solution and I'm pretty sure that there are plenty of tools out there that can help you in doing that, and maybe some of them can be integrated with OSB in some way...
    Cheers,
    Vlad

  • Specify the port in the client in a TCP connection

    Hi,
    I am programming an application using TCP sockets. I have programmed a server whith a SocketServer(port) and is waiting for client's requests (the server is a public host in the Internet). The client connect to the server by means of the method:
    Socket s = new Socket(host, port);
    That works correctly, but now I want to specify the port in the client. The client's PC in a machine on the Internet and it has a public IP. I tried to use the method:
    Socket(String host, int port, InetAddress localAddr, int localPort)
    where localAddr is the local IP of the client' PC (because I cannot know the public IP).
    However, it doesn't work this method and the client cannot connect to the server. The problem is that I want to specify the port in the client in the socket TCP connection when I try to connect to the host.
    How can I resolve this problem?
    Thaks

    I want to specify the port in the clientWhy?

  • Limit of concurrent tcp connections for 2012 Essential

    Hello!
    I looking for what is the max number of concurrent tcp connections on windows 2012 r2 essential..
    I didn'f find answers on here or on the web
    Any help wold be appreciate.
    thanks

    Hi,
    There is no official article related to that. However, based on my experience, there is a registry key to define the maximum number of connections that TCP can have open simultaneously.
    You can check the key of TcpNumConnections in registry editor under the path below:
    HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters
    If there is no such registry existing, you can add one and configure the value from 0x0–0xFFFFFE(REG_DWORD). (0 means that you cannot establish any connections)
    More information:
    https://technet.microsoft.com/en-us/library/cc938216.aspx
    Best regards,
    Susie
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact [email protected]

  • Socket connection between Java and C

    I want to establish socket connection between Java client and C server (on Unix). Can anybody tell how to do it? Will the socket created in client be available in server. I tried out but there was no response from the server.

    We too can't connect the daemon server written by "c". The phenomena is below.
    << Execution of this Question1.class >> ---------------------------------------
    [kazuyuki@CryptOne tmp]$ java Question1 E 1.2.3.4 MFrame.java 195.211.1.1 15021
    << Output message >> ----------------------------------------------------------
    Quetion1 : flg_ = E
    Quetion1 : key_ = 1.2.3.4
    Quetion1 : fn_ = MFrame.java
    Quetion1 : adr_ = CryptOne.localhost/195.211.1.1
    Quetion1 : port_ = 15021
    java.net.ConnectException: Connection refused
         at java.net.PlainSocketImpl.socketConnect(Native Method)
         at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:350)
         at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:137)
         at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:124)
         at java.net.Socket.<init>(Socket.java:268)
         at java.net.Socket.<init>(Socket.java:122)
         at Question1.UPLOAD(Question1.java:65)
         at Question1.main(Question1.java:155)
    << Question >> ----------------------------------------------------------------
    Why the event "java.net.ConnectException: Connection refused" has occured ?
    The server to connect from Question1 can accept the connection request from
    the client program coded by "c" program. We have written down the daemon server
    program by "c" code tcp/ip socket functions (socket, bind, listen, accept).
    Security manager admits the access from this Question1.class, we have checked.
    Would you like please answer this Connction refuse occurrence ?
                                                                     2002.05.18 11:50:00.0(JST)
                                                                     K.Masuda
    << Java client code>> -------------------------------------------------
         (c)Copyright     All rights reserved.
              K.Masuda     2002.05.18
                   << Question1.java >>
    import     java.lang.String;
    import     java.io.InputStream;
    import     java.io.OutputStream;
    import     java.io.DataInputStream;
    import     java.io.DataOutputStream;
    import     java.io.FileInputStream;
    import     java.io.FileOutputStream;
    import     java.io.IOException;
    import     java.io.FileNotFoundException;
    import     java.net.Socket;
    import     java.net.InetAddress;
    import     java.net.UnknownHostException;
    import     java.net.ConnectException;
    import     java.net.NoRouteToHostException;
    class Question1 {
         char               flg_;
         String               key_;
         String               fn_;
         InetAddress          adr_;
         int                    port_;
         Socket               sock_;
         Question1(
              char          flg,
              String          key,
              String          fn,
              String          adr,
              int               port
              flg_     = flg;     
              key_     = key;
              fn_          = fn;
              try{
                   adr_     = InetAddress.getByName( adr );
              catch( UnknownHostException e ){
                   e.printStackTrace();
              port_     = port;
    System.out.println( "Quetion1 : flg_ = " + flg_ );
    System.out.println( "Quetion1 : key_ = " + key_ );
    System.out.println( "Quetion1 : fn_ = " + fn_ );
    System.out.println( "Quetion1 : adr_ = " + adr_ );
    System.out.println( "Quetion1 : port_ = " + port_ );
         public void UPLOAD(
              try{
                   sock_     = new Socket( adr_, port_ );
                   UpLoad();
                   DnLoad();
                   sock_.close();
              catch( UnknownHostException e ){
                   e.printStackTrace();
              catch( ConnectException e ){
                   e.printStackTrace();
              catch( NoRouteToHostException e ){
                   e.printStackTrace();
              catch( IOException e ){
                   e.printStackTrace();
         public void UpLoad(
              byte[]                         buf          = new byte[ 512 ];
              int                              rlen;
              int                              wlen;
              try {
                   OutputStream          sos          = sock_.getOutputStream();
                   FileInputStream          fis          = new FileInputStream( fn_ );
                   DataInputStream          dis          = new DataInputStream( fis );
                   DataOutputStream     dos          = new DataOutputStream( sos );
                   while( ( rlen =     dis.read( buf, 0, buf.length ) ) >= 0 ){
                        dos.write( buf, 0, rlen );
                   dis.close();
                   dos.close();
                   fis.close();
                   sos.close();
              catch( IOException e ){
                   e.printStackTrace();
         public void DnLoad(
              byte[]                         buf          = new byte[ 512 ];
              int                              rlen;
              int                              wlen;
              try {
                   InputStream               sis          = sock_.getInputStream();
                   FileOutputStream     fos          = new FileOutputStream( fn_ + ".cry" );
                   DataInputStream          dis          = new DataInputStream( sis );
                   DataOutputStream     dos          = new DataOutputStream( fos );
                   while( ( rlen =     dis.read( buf, 0, buf.length ) ) >= 0 ){
                        dos.write( buf, 0, rlen );
                   dis.close();
                   dos.close();
                   fos.close();
                   sis.close();
              catch( IOException e ){
                   e.printStackTrace();
         public static void main(
              String[] args
              char[]     chrs     = ( new String( args[ 0 ] ) ).toCharArray();
              Question1     clnt     = new Question1(
                                                                     // E or D
                                            chrs[ 0 ],
                                            args[ 1 ],               // key string
                                            args[ 2 ],               // file to be processed
                                            args[ 3 ],               // IP address
                                                                     // port
                                            Integer.parseInt( args[ 4 ] )
              clnt.UPLOAD();
    }

  • TCP connection closed but a child process of SQL Server may be holding a duplicate of the connection's socket in SQL2008R2

    Hello,
    I do get the below SQL error in production environment intermittently:
    TCP connection closed but a child process of SQL Server may be holding a duplicate of the connection's socket.  Consider enabling the TcpAbortiveClose SQL Server registry setting and restarting SQL Server. If the problem persists, contact Technical
    Support.
    According to the post I search in MSDN, the above error is fixed in SQL2008R-CU6, but I have SQL2008R2-SP02 CU09 patch in production environment and the above error still occurred intermittently. I am running SQL2008R2 SP02 CU09 patch with Windows 2008R2-SP01.
    I would like to know if anyone has  the same error happened to their SQL environment after applied SQL2008R2-SP02 CU06 patch and later.
    Any suggestion would be helpful.
    Best regards,
    PL.

    Hello,
    What happen if you apply the changes on the registry explained on the workaround section of the following article?
    http://support.microsoft.com/kb/2491214
    Hope this helps.
    Regards,
    Alberto Morillo
    SQLCoffee.com

  • Java Application Server 9 - TCP connections

    I have installed Sun Java Application Server 9 and I see that the java process that is started has a lot (more than 30) of TCP connections with a local and a remote address that are both the hostname of the machine that run JAS.
    Can someone tell me what are these connections and if there is a way to decrease the amount of these connections?
    Thank you

    I have installed Sun Java Application Server 9 and I see that the java process that is started has a lot (more than 30) of TCP connections with a local and a remote address that are both the hostname of the machine that run JAS.
    Can someone tell me what are these connections and if there is a way to decrease the amount of these connections?
    Thank you

  • Using Sockets TCP/IP to connect through Proxies and Firewalls

    How to do in a Client/server Application using Sockets TCP/IP to connect through Proxies and Firewalls?
    How to implement the HTTP Tunnelling in this case?
    the code in Client to connect to server is:
    SSLSocketFactory sslFact = (SSLSocketFactory)SSLSocketFactory.getDefault();
                   socket = (SSLSocket)sslFact.createSocket(c.site, c.PORT);
              String [] enabledCipher = socket.getSupportedCipherSuites ();     
                   socket.setEnabledCipherSuites (enabledCipher);
                   out = new ObjectOutputStream(socket.getOutputStream());
                   in = new ObjectInputStream(socket.getInputStream());
    The Server is an executable Standalone Application with a main Function � How to do to convert this Server in a Servlet Application?
    the code in Server to wait client connections is:
    Runtime.getRuntime().addShutdownHook(new ShutdownThread(this));
              try {
                   SSLServerSocketFactory factory = (ServerSocketFactory) SSLServerSocketFactory.getDefault();
                   SSLServerSocket sslIncoming =
                        (SSLServerSocket) factory.createServerSocket (PORT);
                   String [] enabledCipher = sslIncoming.getSupportedCipherSuites ();
                   sslIncoming.setEnabledCipherSuites (enabledCipher);
              while(running) {
                        SSLSocket s = (SSLSocket)sslIncoming.accept();
                   newUser(s, pauseSyn);
              } catch (IOException e) { System.out.println("Error: " + e); }
    some links or code sample?
    Thanks in Advance

    Did you see this: Networking Properties?
    Including
    SOCKS protocol support settings
    and
    http.proxyHost (default: <none>)
    http.proxyPort (default: 80 if http.proxyHost specified)
    http.nonProxyHosts (default: <none>
    ftp.proxyHost (default: <none>)
    ftp.proxyPort (default: 80 if ftp.proxyHost specified)
    ftp.nonProxyHosts (default: <none>)

  • WAE 674 Max TCP Connections

    Does anyone know how many TCP connections the 674 will support with various memory options?
    TIA
    mike

    Mike,
    The WAE-674 will support the following memory/connection options:
    4GB = 2,000 Connections
    8GB = 6,000 Connections
    Regards,
    Zach

  • Resolving a TCP connection "slowdown" problem

    SuSE 9.3, stock kernel
    Intel architecture
    Jrockit-R26.4.0-jdk1.5.0_06-linux-ia32
    I have a problem that appears to be localized in Jrockit (or
    localized in the application, which is localized in Jrockit), where a
    persistent and high-volume TCP connection slows down over the course
    of about an hour--and eventually, effectively halts.
    The TCP traffic is a stream of data, arriving at a near-constant rate
    of about 16K bytes per second, with the receiving end (with the JVM
    and app) strictly sending TCP ACKs in reply.
    Restarting the sending process, or shutting down and restarting the
    connection with the JVM / app, both restore the connection to full
    speed until, over the course of perhaps an hour (sometimes more,
    sometimes less) the same symptoms appear.
    The symptoms in network packet traces are that when the connection is
    first opened, the sender transmits packets at the full MTU of the
    Ethernet segment. Gradually, the number of full-MTU sized packets
    are replaced with packets much smaller packets, until most packets
    range from 1 to 4 bytes with the occasional 3xx-4xx byte packet and
    the odd offlier of a full-MTU packet size.
    Supporting symptoms of interest:
    1) The TCP window does not shrink
    2) The CPU on the JVM/app side tops out at around 20%, even with
    mySQL running on the machine
    3) The interval between successive ACKs transmitted from the JVM/app
    size generally narrows over the course of the connection
    4) TCP send queue on the sender becomes saturated (pegged at 90+ K)
    5) TCP receive queue on the JVM/app side is almost always 0, and when
    it is not zero is bursts up to a low number (<50) and then almost
    immediately returns to 0
    6) The app does not appear to present any general symptoms of
    slowness; the rate of writes to the database does not appear to slow.
    The writes are threaded and multiplexed
    [4] strongly implies that the slowness is caused by the JVM/app side,
    since if the sender app was slowing down for some reason its TCP send
    queue would not be saturated.
    I can copiously document everything stated, and additionally provide
    much additional detail.
    Any guidance on how to suss out role Jrockit or the app are playing
    in this little drama would be very deeply appreciated.

    Asked around and it seems unlikely that this is a JVM issue. We have never heard of this behavior before, and the network layer in the JVM doesn't do anything with MTU iirc with the possible exception of manual changes to socket options. It seems more likely that this is caused by the IP stack, the NIC device driver or something in the network configuration. Try making some changes here and see what happens. For instance:
    1) Run client and server on the same machine, communicating through loopback
    2) Try another Linux distro (CentOS 4.3, for instance)
    3) Try a different NIC and/or a different device driver
    In your Java code, check that you are closing all Socket objects properly. Leaving them to be closed by a finalizer can delay closing sockets resulting in a native resource leak. I don't see how that would cause the issue you describe, but you never know...

  • TCP connect consumes 80% of CPU load

    Hello!
    I've done some profiling on a Java application and i see that 80% of the time the application has on the CPU is used for establishing a TCP connection.
      Socket c;
      c.connect("",xxxx);The application performes several hundreds of connect per minute, but most of them take about 5 sec or less, but som uses the CPU for more than 130 seconds!!
    Could, i suspect it too be a problem with the network card beeing overloaded and will try wit multiple NIC's. But does anybody have any experience with this??? and maybe point out some improvements.

    Hello!
    Should have mentioned it.. we are using a
    ThreadPoolExecutor with 1000 threads in the core. But
    shall look into that. thanx :-)
    There may be some improvements that can be done in
    that areaThis doesn't have anything to do with what I am talking about. I am talking about a pool of open connections (sockets) not a pool of working threads.
    Here is the thing when you (in a program) tell a socket to close the OS gets told that the socket is no longer in use and should be closed. The OS then closes the socket but doesn't actually release the allocated resources until it feels like it. It feels like it when it (a) has some spare time with nothing else to do or (b) it has to reclaim the resources because something else needs them.
    In short the OS final clean up of socket resources is rather akin to garbage collection by the JVM... it will happen but not neccessarily right away and you really can't do anything about that.
    Let me make this 100% clear. This is NOT a Java problem. This is an OS "problem". Although it's not really a problem either. Under most sensible scenarios that model works just fine... your problem is that you are doing something foolish.
    Creating and disposing of sockets is an intensive task for the OS. The queue of sockets waiting to be finally disposed of by the OS grows and grows while it is busy creating new sockets for you until eventually it HAS to clean up in order to give you a new socket. Then you pay a big penalty in time while the OS does it's garbage collection.
    So in summary as it goes this situation is insolvable. What you need to do is not be creating and destroying hundreds of sockets every second. How can you do this? By using a pool of already open sockets that are shared among your various threads.

  • Polling gpib/enet unit over tcp/ip using java

    I understand that there is a linux driver for the gpib/enet product. Since I assume this device is polled over a tcp/ip connection, do I need to do this in C, ot can I establish a socket connection using java ? If so, what is the driver for ? is it just to assign an ip address and other setup functions ?
    Thanks
    John Adams

    Hi John,
    You do not need to do this in C. In fact you can do it in just about any language. The librarys are exported to a shared object, so as long as your language can make calls to a .so, you are good to go. I am positive that java has this capability.
    Hope this helps out! If you need the driver, it is available at www.ni.com/linux.
    Best Regards,
    Aaron K.
    Application Engineer
    National Instruments

  • Windows XP doesnt  detect broken TCP connection

    Hi Guys,
    I have a client and a server. When they are both on a linux or both on a Windows machines there is no problem.
    When the server is on linux and the client is on Windows XP, when the server goes down, the client does not recieve a SocketException.Connection Reset like it should.
    It works fine otherwise, does anyone know why Windows cant see the TCP connection breaking if the server is on linux?

    Java's platform independence cannot shield you from all variations in the implementation of the TCP/IP stack in the underlying operating system.
    If you need to do special tricks for different operating systems chances are you are doing something in a non-optimal way. For the vast majority of programmers TCP/IP "Just Works". You open your sockets, do I/O on them, eventually close them.
    If you write into a socket whose peer has done receive shutdown you eventually get an IOException (I'll guesstimate within one or three minutes absolute worst case). If you don't get the IOException then likely your program has a bug, such as ignoring exceptions. Far lesser likelihood is OS bug.
    When you say "server goes down" do you mean the OS goes down (as in unplug the network connector), or the OS is shut down with a "shutdown" command, or the program is closed? TCP/IP will behave differently if the remote OS is forcefully brought down vs. the program exits and OS remains running. A "shutdown" command may exhibit either behaviour, depending on OS implementation and random timing effects.

Maybe you are looking for

  • Error while saving a version

    Hi , I have susscefully restored and backed up a version but while saving the version in Target environment I get error like. Error message:14090:cannot mark version 740 as deleted.it does not exist in repository. Please advise.

  • Investment grant on asset

    Hi all, I would like to know how it could be possible to integrate investment grant on a legacy asset. I have two kind of assets : asset capitalized on a previous fiscal year asset capitalized on the current fiscal year Integrating investment grant f

  • Problem with multiple downloads of photoshop cs5!! help!!

    Hi, I have adobe photoshop cs5 which i download from the adobe website. i downloaded it on my laptop, which has since stopped working properly. so i deactivated it permanently like a website said i should. i already have creative cloud on my new lapt

  • Change default information after Work Inbox

    Hi, So I'm not sure if I'm asking the right questions but I'm trying to understand what configuration or program is responsible for the information I see after clicking on a Work Inbox request.  Basically I did all the configuration (workflow) for EA

  • Images inside slideshow 'jump'

    It seems that the image in my slideshows 'jump' or resize by a pixel with each new slide. Any help with this and thanks in advance.