Datasheet
API in C using winsock
64
writeWord(fdSock, "");
}
/********************************************************************
* Read a message length from the socket
*
* 80 = 10000000 (2 character encoded length)
* C0 = 11000000 (3 character encoded length)
* E0 = 11100000 (4 character encoded length)
*
* Message length is returned
********************************************************************/
int readLen(int fdSock)
{
char cFirstChar; // first character read from socket
char *cLength; // length of next message to read...will be cast to int at the end
int *iLen; // calculated length of next message (Cast to int)
cLength = calloc(sizeof(int), 1);
DEBUG ? printf("start readLen()\n") : 0;
recv(fdSock, &cFirstChar, 1, 0);
DEBUG ? printf("byte1 = %#x\n", cFirstChar) : 0;
// read 4 bytes
// this code SHOULD work, but is untested...
if ((cFirstChar & 0xE0) == 0xE0)
{
DEBUG ? printf("4-byte encoded length\n") : 0;
if (iLittleEndian)
{
cLength[3] = cFirstChar;
cLength[3] &= 0x1f; // mask out the 1st 3 bits
recv(fdSock, &cLength[2], 1, 0);
recv(fdSock, &cLength[1], 1, 0);
recv(fdSock, &cLength[0], 1, 0);
}
else
{
cLength[0] = cFirstChar;
cLength[0] &= 0x1f; // mask out the 1st 3 bits










