0

I send long number via UDP.

    LinkedQueue Q = new LinkedQueue<ByteBuffer>();
    while (this._run) {
    udp_socket.receive(packet);
      if (packet.getLength() > 0) {
       ByteBuffer bb = ByteBuffer.wrap(buf, 0, packet.getLength());     
               Q.add(bb);
          }
    }

//udp close. I remove data from Queue, but all ByteBuffers have same value.

    while(!Q.isEmpty){
      ByteBuffer b = Q.remove();
      b.getLong();//same value
    }

Why i receive same value? Any Suggest?

Anh Tuan
  • 1
  • 1

1 Answers1

1

Does your byte buffer consists of just one long?

Probably not, my guess is that you put a bit too much for just one long in there. And that's why it gives you same values on first sizeof(long) bytes.

What you need to do is to keep calling .getLong() until you hit the end of the buffer.

See the docs.

nullpotent
  • 9,162
  • 1
  • 31
  • 42