0
我要创建套接字连接多设备,和我有一个接受回拨功能如何在AcceptCallBack创建新的线程时套接字创建iOS中
void AcceptCallBack(
CFSocketRef socket,
CFSocketCallBackType type,
CFDataRef address,
const void *data,
void *info)
{
CFReadStreamRef readStream = NULL;
CFWriteStreamRef writeStream = NULL;
CFIndex bytes;
UInt8 buffer[128];
UInt8 recv_len = 0, send_len = 0;
/* The native socket, used for various operations */
CFSocketNativeHandle sock = *(CFSocketNativeHandle *) data;
/* The punch line we stored in the socket context */
char *punchline = info;
/* Create the read and write streams for the socket */
CFStreamCreatePairWithSocket(kCFAllocatorDefault, sock,
&readStream, &writeStream);
if (!readStream || !writeStream) {
close(sock);
fprintf(stderr, "CFStreamCreatePairWithSocket() failed\n");
return;
}
CFReadStreamOpen(readStream);
CFWriteStreamOpen(writeStream);
/* Wait for the client to finish sending the joke; wait for newline */
// How to create a new IOS thread from here to read data from client.
}
我想从客户端监听数据创建NSThread。因为这是一个C++函数,我无法从对象C访问变量。 谢谢。
下面的答案是否有帮助? – Echelon 2014-09-08 09:35:54