title: java tcp socket can't send file to server side
body: <p>I'm new to <b>java socket programming</b>, this program allows TCP server to have a multi-thread that can run concurrently. I try to send the txt file from one client(has another client that will sent file at the same time) to the server side and ask server to send "ok" status message back to client side. But it seems that the server can't receive any file from the client and the strange thing is <b>if i delete </b>the <code>receiveFile()</code> method in my client class, the server is able to recieve the file from client. Can somebody help me?</p>
  
  <p>Server.class</p>
  
  <pre><code>import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.io.OutputStream;
  import java.io.PrintWriter;
  import java.net.ServerSocket;
  import java.net.Socket;
  import java.net.SocketException;
  
  
  public class ConcurrentServer {
  
      public static void main(String args[]) throws IOException
      {
        int portNumber = 20020;
  
        ServerSocket serverSocket = new ServerSocket(portNumber);
  
  
        while ( true ) {
  
          new ServerConnection(serverSocket.accept()).start();
        } 
  
      }
  
  }
  
  class ServerConnection extends Thread
  {
    Socket clientSocket;  
  
    ServerConnection (Socket clientSocket) throws SocketException
    {
      this.clientSocket = clientSocket;
      setPriority(NORM_PRIORITY - 1);     
    } 
  
  
  public void run()
  {
      try{
          BufferedReader inFromClient = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
  
          OutputStream outToClient = clientSocket.getOutputStream();
  
          PrintWriter printOutPut = new PrintWriter(outToClient,true);
  
          while(inFromClient.ready())
          {
              String request = inFromClient.readLine();
              System.out.println(request);
              System.out.println("test");
          }   
          printOutPut.write("HTTP/1.1 200 OK\nConnection: close\n\n");
          printOutPut.write("&lt;b&gt; Hello sends from Server");
  
  
          printOutPut.flush();
          printOutPut.close();
  
          clientSocket.close();
      }
      catch (Exception e) {
          System.out.println(e.getMessage());
          e.printStackTrace();
          }
  }
  }
  </code></pre>
  
  <p>Client.class</p>
  
  <pre><code>import java.io.BufferedReader;
  import java.io.FileNotFoundException;
  import java.io.FileReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.io.PrintWriter;
  import java.net.Socket;
  
  
   public class SmallFileClient {
  
  static String file="test.txt";
  static PrintWriter outToServer;
  static Socket socket;
  public static void main(String[] args) throws IOException
  {
      final int PORT=20020;
      String serverHostname = new String("127.0.0.1");
  
      socket = new Socket(serverHostname, PORT);
      outToServer = new PrintWriter(socket.getOutputStream(),true);
  
      sendFile();
      receiveFile();
  
      outToServer.flush();
      outToServer.close();
      socket.close();
  
  }
  //read file and send file to server
  public static void sendFile() throws IOException
  {
      BufferedReader br=new BufferedReader(new FileReader(file));
      try
      {
          String line = br.readLine();
          while(line!=null)
          {
              //send line to server
              outToServer.write(line);
              line=br.readLine();
          }
  
      }catch (Exception e){System.out.println("!!!!");}
  
      br.close();
  }
  //get reply from server and print it out
  public static void receiveFile() throws IOException
  {
      BufferedReader brComingFromServer = new BufferedReader(new InputStreamReader(socket.getInputStream()));
      try
      {
          String inline = brComingFromServer.readLine();
          while(inline!=null)
          {
              System.out.println(inline);
              inline = brComingFromServer.readLine();
          }
      }catch (Exception e){}
  }
  }
  </code></pre>