views:

1442

answers:

6

Hi guys/girls,

I was wondering if anyone knows of a combined Objective-C Bonjour/TCP stack out there, that would allow me to forget about managing sockets, broadcasting services etc and instead let me just host a service and/or get a list of existing services and connect to one. Then just continue by sending messages either to specific clients from the server side or to the server from a client.

I presume any received messages and/or discovered services would be sent to me via delegate methods and doing the rest of the dirty work would be up to the stack.

I realize this is not all that tough to implement myself and I already have some of it done, but it would make a lot more sense to use a mature framework.

Extra points if it's iPhone compatible.

A: 

What about using the NSNetServices that's built in to both iPhone and OSX? That does all the work of publishing/subscribing Bonjour services.

Of course, if you're publishing a service, you need a socket to be communicated with, and depending on the protocol you're using, the way you handle incoming messages (and whether there are responses etc.) means that you have to have some knowledge a-priori of what that messaging infrastructure is.

If you can't even be bothered to write that, then hosting something over that de-facto all encompassing protocol, HTTP, is probably the way forward. You can just host your own mini webserver on the device and let HTTP requests do the talking. But the implementation of the service is orthogonal to the discovery of that service.

AlBlue
Not really what I had in mind. What I meant is some kind of class/framework that would take care of all the TCP low level stuff and tie it together with Bonjour (not a problem really, I'm using NSNetServices at the moment anyway). I'd still receive the raw data and respond as needed.The idea would simply be to have the framework use bonjour to discover the server and then create a channel of communication without me having to worry about initializing sockets, queueing reads for them and so on.In all likelihood something like this exists.
Joonas Trussmann
Right, like I said - you can use an HTTP server to deal with the protocol and comms layers, and hook into that itself. There's several examples in the Developer sample code that you could adapt to do the same.
AlBlue
A: 

There is ConnectionKit, which can make things much easier for communication via FTP, HTTP, SFTP, WebDAV and Amazon S3. It doesn't support the iPhone directly, since Cocoa is one of its dependencies, but I imagine it's portable. I'm not sure if this would be of any use in your case, but thought I'd throw it out there just in case.

Wilco
A: 

What about using AsyncSocket. I have not used it personally but it seems to be the perfect choice for you.

Monobono
It's a nice library, but there's still quite a bit of low-levelish messing around.
Joonas Trussmann
+1  A: 

I'd say "do it yourself".

If you don't think that the requirements that you listed in the question will change, then a simple but well-tested implementation of a socket server+netservices and a wrapper for socket+streams will do just fine - you might not even need a "framework" per se.

I've implemented something similar for a tutorial and have been using it in a couple of different projects so far. You are looking at about 200 lines of code for a TCP socket server, and about 300 lines for a Connection class (with delegates and all that).

Byteclub
This really got me moving in the right direction.Then I also discovered MYNetwork in your comments section:http://bitbucket.org/snej/mynetwork/wiki/HomeBasically does everything I asked for and even comes with an (optional) communications protocol.
Joonas Trussmann
+1  A: 

Check out Apple's WiTap example app for iPhone. Many of the structures you are asking for already exist there. You can find it off of the iPhone Dev Center.

fbrereto
A: 

Sounds like you are looking for the GameKit Framework included in the iPhone SDK. GameKit, via GKSession, provides exactly what you are looking for. There is much documentation out there, but the official Apple guide is a great place to start.

Zack