title: How to send multiple objects to socket in Java
body: <p>Can anyone please advise how to send multiple serialized objects in java over a socket to a server?<br>
  currently my server gets always only the first object.</p>
  
  <p><strong>Client side:</strong></p>
  
  <pre><code>public void communicate() throws UnknownHostException, IOException {
      carClientSocket = new Socket("localhost", 4444);
      carClientOR = new ObjectOutputStream(carClientSocket.getOutputStream());
  
      Car[] CarList = new Car[11];
      for ( int i = 1; i &lt;=10; i++ ) {
          //Car alpha;
          CarList[i] = new Car("Alpha Romeo","GTI",1999+i);
      }
      for ( int i =1; i&lt;= 10; i++) {
          carClientOR.writeObject(CarList[i]);
          carClientOR.flush();
          //carClientOR.reset();
      }
      carClientSocket.close();
  }
  </code></pre>
  
  <p><strong>Server Side</strong></p>
  
  <pre><code>public void communicate() throws IOException, ClassNotFoundException {
  CarServerSocket = new ServerSocket(4444);
      System.out.println("Server is ready and waiting for connection from client..\n");
      while (true) { 
          carSocket = CarServerSocket.accept();
          System.out.println("Server Connected");
          carServerIR = new ObjectInputStream(carSocket.getInputStream());
          Car alpha1 = (Car) carServerIR.readObject();
          System.out.println("Object received from car clinet: " + alpha1.getCarBrad() + " " + alpha1.getCarModel() + " " + alpha1.getCarYear());
      }
      //carSocket.close();
      //CarServerSocket.close();
  }
  </code></pre>