title: Using ByteArrayLengthHeaderSerializer with java.net.Socket client
body: <p>I am trying to connect a simple java.net.Socket TCP client to a Spring Integration TCP server using a ByteArrayLengthHeaderSerializer. </p>
  
  <p>Here is the relevant client code snippet:</p>
  
  <pre><code>    Socket socket = null;
  
      OutputStream out = null;
      InputStream in = null;
  
      try {
          socket = new Socket(host, port);
  
          out = new BufferedOutputStream(socket.getOutputStream());
          in = new BufferedInputStream(socket.getInputStream());
          byte[] lengthBuf = new byte[4];
          int size = in.read(lengthBuf, 0, lengthBuf.length);
  
          ByteArrayInputStream bis = new ByteArrayInputStream(lengthBuf);
          ObjectInputStream ois =  new ObjectInputStream(bis);
          int dataSize = ois.readInt();
  
          System.out.println("Got size: " + dataSize);
  
          byte[] dataBuffer = new byte[dataSize];
  
          int dataRead = in.read(dataBuffer, 0, dataBuffer.length);
  
          bis = new ByteArrayInputStream(dataBuffer);
          ois =  new ObjectInputStream(bis);
          String data = (String) ois.readObject();
  
          System.out.println("read " + dataRead + " bytes, got data: " + data);
  </code></pre>
  
  <p>Here is the server side configuration:</p>
  
  <pre><code>@MessagingGateway(defaultRequestChannel="toTcp")
  public interface Gateway {
      void send(@Payload byte[] data, @Header(IpHeaders.CONNECTION_ID) String connectionId);
  }
  
  @Bean
  public AbstractServerConnectionFactory serverFactory() {
      AbstractServerConnectionFactory connectionFactory = new TcpNetServerConnectionFactory(port);
  
      ByteArrayLengthHeaderSerializer serDeser = new ByteArrayLengthHeaderSerializer(); 
      connectionFactory.setSerializer(serDeser);
      connectionFactory.setDeserializer(serDeser);
  
      return connectionFactory;
  }
  
  @Bean
  public TcpReceivingChannelAdapter inboundAdapter(AbstractServerConnectionFactory connectionFactory) {
      TcpReceivingChannelAdapter inbound = new TcpReceivingChannelAdapter();
  
      inbound.setConnectionFactory(connectionFactory);
      inbound.setOutputChannel(fromTcp());
  
      return inbound;
  }
  </code></pre>
  
  <p>and the calling code:</p>
  
  <pre><code>public void send(String data, String header) throws IOException {
          ByteArrayOutputStream bos = new ByteArrayOutputStream();
          try (ObjectOutputStream oos = new ObjectOutputStream(bos)) {                
              System.out.println("data.length is " + data.length());
              oos.writeObject(data);
  
              byte[] bytes = bos.toByteArray();
              gateway.send(bytes, header);
          }
  }
  </code></pre>
  
  <p>When I send the data (e.g. 'abc') I get (on the client side) this error: 
  <code>invalid stream header: 0000000A</code>
  On the server side I get:</p>
  
  <pre><code>SoftEndOfStreamException: Stream closed between payloads
  </code></pre>
  
  <p>What am I doing wrong?</p>