On Dec 25, 2013, at 7:26 AM, Eric Wing <ewmail...@gmail.com> wrote:

> I can publish my iPhone via Bonjour and make my Mac discover and
> resolve the address. I try to create a NSURLSessionDownloadTask on my
> Mac and a NSURLSessionUploadTask on my iPhone.

That won’t work, because both of those are acting as HTTP clients (one sending 
a GET, the other probably a PUT.) Unless one of them acts as a server instead, 
they can’t talk to each other.

All Bonjour does is advertise the availability of a listener/server/service on 
a port. But it doesn’t actually _create_ that listener — that’s your 
responsibility. You have to run some kind of server code that will bind to that 
port, accept connections, and speak the desired protocol.

The problem is, Apple doesn’t include any high-level APIs for running such a 
server. Most commonly people want to serve HTTP. You can cobble together a 
crude HTTP server using CFStream and CFHTTPMessage, but there are a lot of 
details involved in making one that will work for real (i.e. well enough to 
talk to a browser.) Or you could build a very simple custom protocol if all you 
need to do is transfer a blob of data.

Take a look at Apple’s PictureSharing sample code, which shows how to set up a 
basic server and client to send data.
If you want to run a real HTTP server, the best package I know of is 
CocoaHTTPServer (find it on Github.)

—Jens
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to