title: Send multiple files using socket
body: <p>I'm trying to send multiple files from client to server using socket
  but when I click upload button it adds only one file
  and the second click adds the second. This is my code:</p>
  
  <p><strong>client</strong></p>
  
  <pre><code>  void SendFile (String St, String Na) throws IOException{
  
                      Socket sock = new Socket("127.0.0.1", 1112);
                      //ObjectOutputStream out = new ObjectOutputStream(sock.getOutputStream());
                      //outStream.writeObject("test message #");
                      //outStream.flush();
                      //FileInputStream Fi =  null;
  
              try {
                  // TODO add your handling code here:
                  FileInputStream Fi = new FileInputStream(St);
  
                  byte [] Buffer = new byte[Fi.available()];
  
                  Fi.read(Buffer);
                  ObjectOutputStream out = new ObjectOutputStream(sock.getOutputStream());
  
                  out.writeObject(Buffer);
                  out.flush();
                  out.close();
                  //outStream.writeObject(Buffer);
                  write.println("Send:File: " + Na);
  
                  write.flush();
  
  
  
  
  
              } catch (FileNotFoundException ex) {
                  Logger.getLogger(Add_Book.class.getName()).log(Level.SEVERE, null, ex);
              } catch (IOException ex) {
                  Logger.getLogger(Add_Book.class.getName()).log(Level.SEVERE, null, ex);
  
  
                  }
                  catch (Exception ex) 
                  {
                      System.out.println("error connecting to server");
                  }
               sock.close();
          }
             `
  </code></pre>
  
  <p><strong>call method:</strong> </p>
  
  <pre><code>SendFile(CoverPath,CoverName);
  SendFile(BookPath,BookName); 
  </code></pre>
  
  <p><strong>Server</strong></p>
  
  <pre><code>     public class UploadServer implements Runnable 
      {
          @Override
          public void run() 
          {
              clientOutputStreams = new ArrayList();
              users = new ArrayList();  
  try 
              {
                  ServerSocket serverSocket = new ServerSocket(1112);
  
                  while (true) 
                  {
                  Socket clientSocket = serverSocket.accept();
                  ObjectOutputStream Oos = new ObjectOutputStream(clientSocket.getOutputStream());
  
                                  is = clientSocket.getInputStream();
  
                  Thread listener = new Thread(new UploadHandler(clientSocket));
                  listener.start();
                  TextArea.append("Request upload. \n");
                                  ss = clientSocket;
                  }
              }
              catch (Exception ex)
              {
                  TextArea.append("Error making a connection. \n");
              }
  
          }
  }
  
  
   public class UploadHandler implements Runnable 
     {
            ObjectInputStream inputS;
            ObjectInputStream input;
         BufferedReader reader;
         ObjectInputStream Ois;
         Socket sock;
  
  
         byte[] aByte = new byte[1];
          int bytesRead;
  
        public UploadHandler(Socket clientSocket) 
         {
  
              try 
              {
                  sock = clientSocket;
                  inputS = new ObjectInputStream(sock.getInputStream());
                  //input = new ObjectInputStream(sock.getInputStream());
  
              }
              catch (Exception ex) 
              {
                  TextArea.append("Unexpected error... \n");
              }
  
         }
  
         @Override
         public void run() 
         {
  
              try {
  
                    byte [] Buffer = (byte[]) inputS.readObject();
                    FileOutputStream Fi = new FileOutputStream("Uploads\\"+Name);
                    Fi.write(Buffer);
                    System.out.println("Done");
  
                } catch (IOException ex) {
                    Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
                } catch (ClassNotFoundException ex) {
                    Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
                }
  
  
  
  
         }
  
  
        }
  </code></pre>