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);
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.