0

From my PC app I am sending socket data to my iPhone. When the data arrives it is being stored as a signed value instead of unsigned (uint8). So I can't get any values in above 127.

When I send a 0xFF it defaults back to 0x3f.

Is CFReadStreamRead only meant for ASCII characters? If so what would be a replacement?

My code:

CFReadStreamRef readStream = NULL;
CFWriteStreamRef writeStream = NULL;
CFIndex bytes;
UInt8 buffer[128];
UInt8 recv_len = 0;
UInt8 send_len = 0;

//
//Get the native socket that was used
CFSocketNativeHandle sock = *(CFSocketNativeHandle*)data;


//
//Create the read and write streams for this socket
CFStreamCreatePairWithSocket(kCFAllocatorDefault, sock, &readStream, &writeStream);

//
//Check for errors
if (!readStream || !writeStream)
{
    close(sock);
    fprintf(stderr, "CFStreamCreatePairWithSocket failed.");
    return;
}

//
//Open the streams
CFReadStreamOpen(readStream);
CFWriteStreamOpen(writeStream);

//
//Read the command bytes
short command = 0;

memset(buffer, 0, sizeof(buffer));
bytes = CFReadStreamRead(readStream, buffer, 12);

1 Answers1

1

0x3f is ASCII '?'. Are you trying to decode the byte buffer as a UTF-8 string? If so, there's your problem. The CFReadStream API is unlikely to be messing with the data; it's much more likely that you are.

  • As far as I know I am not messing with it. If I put a break point just after the read and inspect the buffer any value over 0x3f gets set to a '?'. – user862821 Jul 26 '11 at 17:59
  • Also, I am not interested in decoding it as a string. I just want the unchanged hex values. – user862821 Jul 26 '11 at 18:00
  • Looks like the testing tool I was using on the windows side was truncating byte values prior to sending it. Although the GUI wasn't indicating such. Beware of this problem on the SimpleCom tools. – user862821 Jul 26 '11 at 20:51