#define DEBUG_ACK
static const int SOCKET_BUFF_SIZE = 64000;
+// Before, it was too short as we were just using 1 byte to receive the length
+// Now, we allocate 4 bytes (a size of integer) to receive the message length
+static const int MSG_LEN_SIZE = 4;
#include <stdio.h>
#include <stdlib.h>
int iLen = _iLen;
size[0] = iLen;
- if (send(m_iSock, size, 1, 0) == -1) {
+ if (send(m_iSock, size, MSG_LEN_SIZE, 0) == -1) {
perror("IoTSocket: Send size error!");
return false;
}
int iTotal = 0;
int iResult = 0;
- char size[1];
+ int size[1];
+
while ((iTotal < 1) && (iResult != -1)) {
- iResult = recv(m_iSock, size, 1, 0);
+ iResult = recv(m_iSock, size, MSG_LEN_SIZE, 0);
iTotal += iResult;
}
if (iResult == -1) {
perror("IoTSocket: Receive size error!");
return NULL;
}
- int iLen = (int) size[0];
+ int iLen = size[0];
+
// To be returned from this method...
*len = iLen;
pVals = new char[iLen];