Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4343746

backlog in ServerSocket(int port,int backlog) works same with 0 and 1.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.2.1
    • core-libs
    • merlin
    • x86
    • windows_95



      Name: skT45625 Date: 06/06/2000


      The Java version iam working with is JDK1.2.1.

      1. backlog parameter in ServerSocket(int port,int backlog) works same with 0
         and 1.
      2. ie., the queue length for backlog = 0 should be null.So that only one
         client can connect at a time and get the service from server.But,
                  ServerSocket(2000,0)
         works similar to ServerSocket(2000,1),say some port 2000,where the queue
         length is 1.(ie.,one client can get the service from server,while other waits
         in the queue.
      3. So,the problem i faced is while trying to use 'ServerSocket(2000,0)' for
         keeping my queue length limited to 0.
      4. The sample source code is,

         //The Server part code follows...
         import java.io.*;
         import java.net.*;
         class Server
         {
           public static void main(String args[]) throws Exception
           {
             /*
                 PROBLEM :
                 ServerSocket ss = new ServerSocket(2000,0) works similar with
                 ServerSocket ss = new ServerSocket(2000,1)
             */
             ServerSocket ss = new ServerSocket(2000,0);
             DataInputStream sin = null;
             Socket s;
             while(true)
             {
               System.out.println("Waiting for connection...");
               s = ss.accept();
               sin = new DataInputStream(s.getInputStream());
               System.out.println("Connected with a client.");
               String str;
               while((str=sin.readLine())==null)
                   Thread.sleep(100);
               s.close();
             }
           }
        }//The Server part code ends here


         //The Client part code follows...
         import java.io.*;
         import java.net.*;
         class Client
         {
           public static void main(String args[]) throws Exception
           {
             System.out.println("Trying to connect with server...");
             Socket c = new Socket("Localhost",2000);
             System.out.println("Connect with server");
             DataInputStream sin = new DataInputStream(System.in);
             String str = sin.readLine();
             PrintStream cout = new PrintStream(c.getOutputStream());
             cout.println(str);
             cout.flush();
             c.close();
           }
         }//The Client part code ends here

      5. Trying to connect two Clients with Server reveals the problem.
      6. Please inform me the details and so that i can get rid off it from my
         work.
         Iam looking forward for your early reply.
         Thank you.
         Yours sincerely,
         A.Sankar.
      (Review ID: 105765)
      ======================================================================

            jccollet Jean-Christophe Collet (Inactive)
            skondamasunw Suresh Kondamareddy (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: