UDP and CFSocket
UDP and CFSocket
- Subject: UDP and CFSocket
- From: Graham Wihlidal <email@hidden>
- Date: Mon, 13 Aug 2001 23:03:06 -0600
Hey list
Sorry for sending the majority of the messages today. :)
I am TRYING to get UDP to work with the CFSocket layer. It binds to the
port, but It refuses to throw any received data into the callback.
Any ideas? I wrote this code with guesswork based on what I did for
TCP\IP
Here is my code: Thanks in advance, Graham
CFSocketRef sock2;
void GS_SOCKET_UDPSTART(void)
{
CFRunLoopSourceRef source;
CFDataRef addr;
CFSocketError theErr;
struct hostent *het = gethostbyname("localhost");
struct sockaddr_in sin;
sock2 = CFSocketCreate(NULL,
PF_INET,
SOCK_DGRAM,
IPPROTO_UDP,
kCFSocketDataCallBack,
GS_SOCKET_UDP_RECV,
NULL);
memset(&sin, 0, sizeof(sin));
memcpy(&sin.sin_addr.s_addr, het->h_addr, sizeof(struct in_addr));
sin.sin_len = sizeof(struct sockaddr_in);
sin.sin_family = AF_INET;
sin.sin_port = htons(9993);
addr = CFDataCreate(NULL, (char *)&sin, sizeof(sin));
theErr = CFSocketConnectToAddress(sock2, addr, 0);
switch (theErr) {
case kCFSocketSuccess:
NSLog(@"UDP Logged in");
source = CFSocketCreateRunLoopSource(NULL, sock2, 0);
CFRunLoopAddSource(CFRunLoopGetCurrent(), source,
kCFRunLoopCommonModes);
break;
case kCFSocketError:
NSLog(@"UDP Error");
break;
default:
NSLog(@"UDP Networking Error");
break;
}
}
GS_SOCKET_UDP_RECV(CFSocketRef s,
CFSocketCallBackType type,
CFDataRef address,
const void *data,
void *info)
{
NSLog(@"Got data?");
}