1 Reply Latest reply on Mar 17, 2007 2:59 AM by EJP

    Server Socket Question ?

    807597
      I have a server client app using SE Java.

      There are 6 types of clients that connect to the server using a socket.

      As it is now i just use 1 server socket to spin off a thread each time any client arrives.

      like so:
      import java.net.ServerSocket;
      import java.io.IOException;
      
      public final class MultiServer5 {
         
          public static void main(String[] args) throws IOException {
              ServerSocket serverSocket = null;
              boolean listening = true;
      
              try {
                  serverSocket = new ServerSocket(4005);
              } catch (IOException e) {
                  System.err.println("Main: Could not listen on port: 4005.");
                  System.exit(-1);
              }
              while (listening)
               new ServerThread5(serverSocket.accept()).start();
              serverSocket.close();
          }
      }
      Then in the Thread I read in what type client it is.

      From there I know what code to run to handle the client.

      They all loop and wait for an update request from the client.

      The way I do it now is to call each client from that one thread but I was thinking and realized it may go smoother if I just use 6 servers and 6 threads 1 - 6 each one handles one of each of the 6 client types.

      each client accesses mySQL using a connection pool.

      The advantage I see doing it the second way is that I don't have to read from the client each time to determine which type client it is and then call more code accordingly.

      Now each of the 6 servers sit and wait on ports A - F for their type client and run 1 of 6 of the threads each having just its procedures for that type client.

      Please let me know which approach is better or the advantages and disadvantages of one verses the other or if there is no real difference either way.