title: Socket closed issues
body: <p>I have a server and client connection using sockets to transfer files, but if I want to be able to send strings to the server from the client upon user JButton actions, it throws socket closed errors (Because I used dos.close() in the Sender() constructor). The problem is, if I don't use dos.close(), the client program won't run/init the UI frame. What am I doing wrong? I need to be able to send files when the program first runs then send data later.</p>
  
  <p>Sender:</p>
  
  <pre><code>public Sender(Socket socket) {
  
      List&lt;File&gt; files = new ArrayList&lt;File&gt;();
      files.add(new File(Directory.getDataPath("default.docx")));
      files.add(new File(Directory.getDataPath("database.db")));
  
      try {
          BufferedOutputStream bos = new BufferedOutputStream(socket.getOutputStream());
          DataOutputStream dos = new DataOutputStream(bos);
          dos.writeInt(files.size());
          for (File file : files) {
              dos.writeLong(file.length());
              dos.writeUTF(file.getName());
              FileInputStream fis = new FileInputStream(file);
              BufferedInputStream bis = new BufferedInputStream(fis);
              int theByte = 0;
              while ((theByte = bis.read()) != -1) { 
                  bos.write(theByte);
              }
              bis.close();
          }
          dos.close(); // If this is disabled, the program won't work.
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>Downloader:</p>
  
  <pre><code>public static byte[] document;
  
  public Downloader(Socket socket) {
      try {
          BufferedInputStream bis = new BufferedInputStream(socket.getInputStream());
          DataInputStream dis = new DataInputStream(bis);
          int filesCount = dis.readInt();
          for (int i = 0; i &lt; filesCount; i++) {
              long size = dis.readLong();
              String fileName = dis.readUTF();
              if (fileName.equals("database.db")) {
                  List&lt;String&gt; data = new ArrayList&lt;String&gt;();
                  BufferedReader reader = new BufferedReader(new InputStreamReader(bis));
                  String line;
                  while ((line = reader.readLine()) != null) {
                      if (line.trim().length() &gt; 0) {
                          data.add(line);
                      }
                  }
                  reader.close();
                  parse(data);
              } else if (fileName.equals("default.docx")) {
                  ByteArrayOutputStream bos = new ByteArrayOutputStream();
                  for (int x = 0; x &lt; size; x++) {
                      bos.write(bis.read());
                  }
                  bos.close();
                  document = bos.toByteArray();
              } 
          }
          //dis.close();
          } catch (Exception e) {
          e.printStackTrace();
      }
  }
  </code></pre>