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

Re-opening a server socket on the same port (after closing prev) does not work

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.1.5
    • core-libs
    • x86
    • windows_nt



      Name: diC59631 Date: 06/11/98


      1. Open a server socket on a port
      2. Open another one on the same port
         -- Correct behaviour. Does not work.
      3. Connect to the server socket
      4. Close the server socket
      5. Open another one on the same port
         -- Fails with address in use exception
         -- Wrong behaviour
      6. Close the socket opened at step 3
      7. Repease step 5
         -- Succeeds.

      Step 5 succeeds under Solaris. JDK1.02 under
      windows NT exhibits the correct behaviour.

      Source to test the above case:
      import java.net.ServerSocket;
      import java.net.Socket;

      public class t {
         public static void main(String args[]) throws Exception {
            ServerSocket s1, s2;
            Socket s, ss;
            
            s1 = new ServerSocket(1099);

            try {
      s2 = new ServerSocket(1099);
      System.out.println("SUCCESS");
      System.in.read();
      return;
            } catch (Exception e) {
      System.out.println("Could not open two listeners at the same port");
      e.printStackTrace();
            }
            
            // Connect to host 1099
            s = new Socket("localhost", 1099);
            ss = s1.accept();
            s1.close();
            System.in.read();
            
            try {
      s2 = new ServerSocket(1099);
      return;
            } catch (Exception e) {
      System.out.println("Could not open two listeners at the same port");
      System.out.println(" even after closing the first listener");
      e.printStackTrace();
            }

            // Nothing at the port
            s.close();
            ss.close();
            
            try {
      s2 = new ServerSocket(1099);
      return;
            } catch (Exception e) {
      System.out.println("This is a serious problem with the OS");
      e.printStackTrace();
            }
         }
      }
      (Review ID: 24672)
      ======================================================================

            michaelm Michael McMahon
            dindrigo Daniel Indrigo (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: