-3

I have a little error wih my netty-server. I need to transfer different byteBuf sizes (the send-buffers capacity is dynamicly increased).

    byte[] buffer = text.getBytes();
    byteBuffer.writeInt(buffer.length);

    if (byteBuffer.capacity() < (byteBuffer.writerIndex() + buffer.length))
        System.out.println("Increased Buffer Capacity to " + byteBuffer.capacity(byteBuffer.capacity() + buffer.length).capacity());

    byteBuffer.writeBytes(buffer);

It outputs the new (increased) capacity of the byteBuf but when the Server reads the byteBufs capacity is not the increased one and it outputs errors.

Thanks for your help

Seb
  • 1
  • 2
  • 1
    Why should the receiver's byte buffer have the same capacity as the sender's? They aren't magic you know. – user207421 Jun 20 '18 at 08:15
  • I know, but my Server outputs a different capacity on receive, i guess it only recieves the default-byteBuf's size. The sendBuf-capacity is bigger than the received – Seb Jun 20 '18 at 08:18
  • 1
    So? Are you expecting `byteBuffer.capacity(byteBuffer.capacity() + buffer.length)` to take effect at the peer too? It doesn't. It's only a local action. – user207421 Jun 20 '18 at 08:19
  • yeah but I think the increased byteBuf-size sent will take effect on a larger transfer-set, but it do not seem to work. Do you have an other possibility to fix the error? – Seb Jun 20 '18 at 08:25
  • I have no idea what you are talking about. – user207421 Jun 20 '18 at 08:26
  • I thought if i Incerease the amount of the bytes sent the amount of received-bytes will increase as well. Do you have n idea how i can transfern different byteBuf sizes? – Seb Jun 20 '18 at 08:29
  • So you thought exactly what I already said didn't happen? Is that it? Clarify. – user207421 Jun 20 '18 at 08:45
  • Yes, you're right. I thought it somehow makes sense. – Seb Jun 20 '18 at 08:50

1 Answers1

0

I fixed my problem by creating an alorithm spliting the fully filled byteBuffer into multiple byteBufs which are send seperatly and reordered and parsed by the server.

Thnk you for your help (EJP)

Seb
  • 1
  • 2