Re: Getting UDP sockets to work
Re: Getting UDP sockets to work
- Subject: Re: Getting UDP sockets to work
- From: Jaime Magiera <email@hidden>
- Date: Mon, 11 Aug 2008 16:08:05 -0400
On Aug 11, 2008, at 3:51 PM, Liwei wrote:
Ah... byte order problems!
But somehow adding htons to the number made the app crash on my side,
and I'm very certain I'm on Intel.
Hi, I don't know if this will help or not, but here is a snippet of
code I use for UDP in one of my apps. It works on XCode 3.1/OSX10.5/
Intel
CFSocketContext socketCtxt = {0, self, NULL, NULL, NULL};
struct sockaddr_in myAddress;
int testPort = (int)[self port];
myAddress.sin_family = AF_INET;
myAddress.sin_port = htons(testPort);
myAddress.sin_addr.s_addr = htonl(INADDR_ANY);
CFDataRef d1 = CFDataCreate(NULL, (UInt8 *)&myAddress, sizeof(struct
sockaddr_in));
CFSocketSignature signature = {PF_INET, SOCK_DGRAM, IPPROTO_UDP, d1};
socket = CFSocketCreateWithSocketSignature(NULL, &signature,
kCFSocketDataCallBack, handleUDPDataFromSocket, &socketCtxt);
CFRunLoopSourceRef source = CFSocketCreateRunLoopSource(NULL, socket,
0);
CFRunLoopRef loop = CFRunLoopGetCurrent();
CFRunLoopAddSource(loop, source, kCFRunLoopDefaultMode);
hope that helps,
Jaime Magiera
Sensory Research
http://www.sensoryresearch.net
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden