On Jun 21, 2005, at 2:02 AM, Heath Raftery wrote: I'm using the socket, bind and sendto calls to establish and send UDP data, and NSFileHandle's readInBackgroundAndNotify to read. Would I be right in discovering readToEndOfFileInBackgroundAndNotify does not apply to UDP?
NSFileHandle is not really designed for datagram-oriented protocols. I would suggest using CFSocket instead, if you wish to receive notifications of data on your run loop.
Something like
CFSocketRef s = CFSocketCreateWithNative(NULL, sock, kCFSocketDataCallBack, dataArrived, NULL); CFRunLoopSourceRef source = CFSocketCreateRunLoopSource(NULL, s, 0); CFRunLoopAddSource(CFRunLoopGetCurrent(), source, kCFRunLoopDefaultMode);
where sock is your UDP socket and
void dataArrived(CFSocketRef s, CFSocketCallBackType type, CFDataRef address, const void *data, void *info) { // this is your callback, data is a CFDataRef containing your data }
Douglas Davidson
|