【发布时间】:2011-07-26 05:51:41
【问题描述】:
我正在从我的 PC 应用程序向我的 iPhone 发送套接字数据。当数据到达时,它被存储为有符号值而不是无符号 (uint8)。所以我无法得到 127 以上的任何值。
当我发送 0xFF 时,它默认返回 0x3f。
CFReadStreamRead 是否仅适用于 ASCII 字符?如果是这样,什么是替代品?
我的代码:
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);
【问题讨论】:
标签: iphone ios4 ios-simulator cfstream