Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do peer-to-peer communication in an iPhone app?

Tags:

ios

iphone

sip

I'm trying to write a simple chat application for the iPhone (as an experiment). Is there a simple way for two devices to discover each others' IP addresses, and given the addresses is there a simple API or protocol that would let me send text messages back and forth?

I've investigated SIP (specifically Sofia and eXosip), but these tools exist as C libraries and are beyond my current ability to port them to the iPhone.

Update: I'm trying to connect two devices over the Internet (i.e. not over Bluetooth or a local wireless network, which is what GameKit does).

like image 610
MusiGenesis Avatar asked Oct 11 '10 20:10

MusiGenesis


2 Answers

You're going to need a server that provides the match making service. Game Center makes this pretty easy, but your users will have to have Game Center accounts.

Alternatively, you can set up an XMPP (formerly Jabber, it's what powers Google Chat) server (I've never done this, but there are several available) and use the XMPP Framework for Cocoa. There are instructions for using it in iPhone apps here.

I'm sure there are other chat servers and client source also available. IRC and Mobile Colloquy come to mind.

Finally, you could write your own server using your favorite server language / framework. This isn't too hard (I've done it myself), but it's far from what I'd call simple, and I wouldn't use it for a production system.

like image 83
Kris Markel Avatar answered Oct 10 '22 15:10

Kris Markel


There is support for exactly this kind of ad-hoc peer-to-peer networking in GameKit. Have a look at the second half of the GameKit documentation for details:

http://developer.apple.com/library/ios/#documentation/...

like image 42
Jake Avatar answered Oct 10 '22 14:10

Jake