• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
UDP and CFSocket
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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?");
}


  • Prev by Date: Re: Selecting objects, help needed...
  • Next by Date: Enabling/Disabling Buttons
  • Previous by thread: Re: flavorTypeHFS with Cocoa
  • Next by thread: Enabling/Disabling Buttons
  • Index(es):
    • Date
    • Thread