title: Sending TCP packets via Netty, Netty is dividing the data into different packets?
body: <p>I'm currently using Netty 4.0.7.Final to write a server that receives images (size: ~10k) over TCP.
  I modified Netty's sample echo client handler to just read a file into bytes, and send it over to my Netty server.</p>
  
  <pre><code>public EchoClientHandler(int firstMessageSize) throws IOException {
      File image = new File("google.jpeg");
      byte[] imageBytes = FileUtils.readFileToByteArray(image);
      byte[] bytes = Base64.encodeBase64(imageBytes);
      String base64 = new String(bytes);
      //System.out.println("base64="+ base64);
      firstMessage = Unpooled.copiedBuffer(base64, CharsetUtil.UTF_8);
  }
  </code></pre>
  
  <p>My test image is 9k, and I can see the whole image is being sent via Netty logging</p>
  
  <pre><code>io.netty.handler.logging.LoggingHandler logMessage
  INFO: [id: 0x132baef0, /127.0.0.1:49710 =&gt; localhost/127.0.0.1:2112] WRITE(11964B)
  </code></pre>
  
  <p>However, when the Netty server receives the message, it seems to be dividing the message into two packets, the first packet is 1024 bytes, and the second one is 10940 bytes, which adds up to 1024+10940 = 11964 bytes (total size of the image)</p>
  
  <pre><code>2013-08-24 22:56:33,700 [nioEventLoopGroup-3-1] INFO  MessageDecoder - capacity = 1024
  2013-08-24 22:56:33,700 [nioEventLoopGroup-3-1] INFO  MessageDecoder - readable bytes = 1024
  2013-08-24 22:56:33,709 [nioEventLoopGroup-3-1] INFO  MessageDecoder - capacity = 16384
  2013-08-24 22:56:33,710 [nioEventLoopGroup-3-1] INFO  MessageDecoder - readable bytes = 10940
  </code></pre>
  
  <p>Here's what my decoder looks like (although I doubt the decoder has anything to do with it, it looks like Netty is handling this before it even reaches the decoder)</p>
  
  <pre><code>public class MessageDecoder extends ByteToMessageDecoder {
  
  private static final Logger LOGGER = LoggerFactory.getLogger(MessageDecoder.class);
  
  @Override
  protected void decode(ChannelHandlerContext ctx, ByteBuf in, List&lt;Object&gt; out) throws Exception {
      // Convert to String first
      LOGGER.info("capacity = " + in.capacity());
      LOGGER.info("readable bytes = " + in.readableBytes());
      String rawString = in.readBytes(in.readableBytes()).toString(CharsetUtil.UTF_8);    
      LOGGER.info("Received base64 String={}", rawString);
  }
  </code></pre>
  
  <p>I also tried large number of files, it looks Netty is always dividing a message into packets of 1024 bytes + whatever size for the rest of the file??</p>
  
  <p><strong>I'm wondering why Netty is doing this ? And is there a way to just get the complete packet in one-go?</strong></p>
  
  <p>Thanks so much.</p>