Java, Convert multiClient ServertSocket to single
<p>Long story short, this code is working Perfectly for me. I would like to change the least possible ( While still doing what i want to do ) . This is a multiclient serversocket, that's working great for me. Only thing i want to change is, change it to singleClient. </p>

<p>So that, Client#1 connects, talks to server, Client#2 tries to connect, but can't talk to server since Client#1 is still connected, once Client#1 Disconnects, Client#2 is now able to connect and talk to Server.  </p>

<p>Right now my code does exactly that except it allows all the clients to connect and talk to server simultaneously, which is what i don't want.
P.s - The client side is working just fine. Just need help with the Serverside, and one last thing, i'm not JavaSavvy, so spoonfeeding is greatly appreciated :$</p>

<pre><code>Socket s=null;
            ServerSocket ss2=null;
            Status = ("Server Listening......");
            try{
                ss2 = new ServerSocket(4445); // can also use static final PORT_NUM , when defined

            }
            catch(IOException e){
            e.printStackTrace();
            System.out.println("Server error");

            }


            ServerThread serverThread = null;
            while(true){
                try{
                    s= ss2.accept();
                   Status = ("connection Established");

                   if (serverThread == null || !serverThread.isAlive()) {
                    ServerThread st=new ServerThread(s);    
                    st.start();
                   }
                   else
                       s.close();
                }

            catch(Exception e){
                e.printStackTrace();
                System.out.println("Connection Error");

            }
            }

        }




            class ServerThread extends Thread{  


                String str = "Hello";
                String line=null;
                BufferedReader  is = null;
                PrintWriter os=null;
                Socket s=null;

                public ServerThread(Socket s){
                    this.s=s;
                }

                public void run() {
                try {
                    BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
                        OutputStream os = s.getOutputStream();
                        PrintWriter pw = new PrintWriter(os, true);
                        pw.println("Hi");
                    line=br.readLine();
                    String input = br.readLine().replaceAll("[^A-Za-z0-9]", "");
                    while ((input = br.readLine()) != null) { //Here is the loop part
                        input = input.replaceAll("[^A-Za-z0-9]", "");
                        if(input.contains("Done")){
                            System.out.println("We closing it");
                            s.close();
                        }
                        else if (input.equals(str)) {
                            System.out.println("We received : " + str);
                            pw.println("Hi");  
                        }
                        if (input.contains(str)){
                                Finite();
                        }
                        if(input.contains("Done")){
                            System.out.println("We closing it");
                            s.close();
                        }
                    }

                } catch (IOException e) {

                    line=this.getName(); //reused String line for getting thread name
                    System.out.println("IO Error/ Client "+line+" terminated abruptly");
                }
                catch(NullPointerException e){
                    line=this.getName(); //reused String line for getting thread name
                    System.out.println("Client "+line+" Closed");
                }

                finally{    
                try{
                    System.out.println("Connection Closing..");
                    if (is!=null){
                        is.close(); 
                        System.out.println(" Socket Input Stream Closed");
                    }

                    if(os!=null){
                        os.close();
                        System.out.println("Socket Out Closed");
                    }
                    if (s!=null){
                    s.close();
                    System.out.println("Socket Closed");
                    }

                    }
                catch(IOException ie){
                    System.out.println("Socket Close Error");
                }
                }//end finally
                }
            }
</code></pre>