• 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
Re: Getting UDP sockets to work
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Re: Getting UDP sockets to work (From: Liwei <email@hidden>)

  • Prev by Date: Re: Getting UDP sockets to work
  • Next by Date: Re: Porting Winsock DHCP Server; is OS/X ignoring Broadcast UDP in recvall()?
  • Previous by thread: Re: Getting UDP sockets to work
  • Next by thread: Re: Porting Winsock DHCP Server; is OS/X ignoring Broadcast UDP in recvall()?
  • Index(es):
    • Date
    • Thread