// Receive until maxlen
if (maxlen>BUFFSIZE) {
System.out.println("IoTSocketClient/Server: Sending more bytes then will fit in buffer! Number of bytes: " + maxlen);
+ // Allocate a bigger array when needed
+ int newLen = 2;
+ while (newLen < maxlen) // Shift until we get a new buffer size that's bigger than maxLen (basically power of 2)
+ newLen = newLen << 1;
+ System.out.println("IoTSocketClient/Server: Allocating a bigger buffer now with size: " + newLen);
+ data = new byte[newLen];
}
val = new byte[maxlen];
while (totalbytes < maxlen)