views:

37

answers:

1

I need to be able to send out a UDP message and also receive one in order to discover SSDP devices on the network from the iPhone.

I know that I need to send the packet to the multicast address and my HTTP request needs to look something like this:

M-SEARCH * HTTP/1.1
Host: 239.255.255.250:1900
Man: ssdp:discover
Mx: 3
ST: "urn:schemas-upnp-org:device:InternetGatewayDevice:1"

From reading the docs it appears that I can do all this with CFNetwork and despite reading (and re-reading the docs) I am struggling to get started. Can anyone recommend and tutorials or code snippets to get me over the initial learning hump?

I've got the CFNetwork programming guide:

http://developer.apple.com/mac/library/documentation/Networking/Conceptual/CFNetwork/CFNetwork.pdf

and Beej's Guide to Network programming Using Internet Sockets:

http://beej.us/guide/bgnet/

Thanks

Dave

P.S.

I am unable to use any of the 3rd party libraries and frameworks in this instance.

A: 

OK, finally done it. Found a class in the public domain (thanks Chris) called AsyncUdpSocket that lets you create a UDP socket which you can then turn on broadcasting and join the multicast address.

There is a nice sendData method, complete with adding to a run loop to prevent blocking.

Hope that helps.

Dave

Magic Bullet Dave