title: how can i send multiple objects through java server socket to php socket?
body: <p>I am trying to send multiple objects through a php socket from a java server.
  Although when i try to send 2 or more json objects to php client, the website just refuses to load. But when i send only one json object, it seems to work fine.</p>
  
  <p>This is the code from my java server: </p>
  
  <pre><code>package org.articron.server;
  import org.json.simple.JSONObject;
  import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.PrintWriter;
  import java.net.Socket;
  
  /**
   * @author Articron | Arno
   *         on 8-8-2015.
   */
  public class TCPConnection implements Runnable {
  
      private Socket client;
      private PrintWriter writer;
      private BufferedReader reader;
      private JSONObject tosend;
      private JSONObject tosend2;
  
      public TCPConnection(Socket client, PrintWriter writer, BufferedReader reader) {
          this.client = client;
          this.writer = writer;
          this.reader = reader;
          tosend = new JSONObject();
          tosend2 = new JSONObject();
          tosend.put("scriptid","2");
          tosend.put("name","mathias@cochet.lol");
  
          tosend2.put("scriptid","1");
          tosend2.put("botname","arno.gerver@gmail.com");
      }
  
      @Override
      public void run() {
          try {
              tosend.writeJSONString(writer);
              tosend2.writeJSONString(writer);
              writer.write("END");
              writer.flush();
              writer.close();
              reader.close();
              client.close();
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>and this is what the php looks like: </p>
  
  <p>
  
  <pre><code>function dataTrans()
  {
      $recieved = array();
      /* Get the port for the WWW service. */
      $service_port = 5678;
  
      /* Get the IP address for the target host. */
      $address = gethostbyname('104.251.212.75');
  
      /* Create a TCP/IP socket. */
      $socket = socket_create(AF_INET, SOCK_STREAM, getprotobyname('tcp'));
      if ($socket === false) {
          echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
      } else {
         // echo "OK.\n";
      }
  
  
      $result = socket_connect($socket, $address, $service_port);
      if ($result === false) {
          echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
      } else {
         // echo "OK.\n";
      }
          do{
          $obj = socket_read($socket, 1024);
              if($obj == 'END'){
                  break;
              }
          array_push($recieved, json_decode($obj));
              }while(true);
      socket_close($socket);
      return $recieved;
  }
  </code></pre>