21

I've been at this for a few days now, and can't seem to find a solution. I want to create a peer to peer network over wifi on iOS. All open source code seems to be supporting running a server or being a client, but there's no code built to support being both - a peer. Is anybody aware of a way I can do this?

JuJoDi
  • 14,627
  • 23
  • 80
  • 126
Andrew
  • 15,935
  • 28
  • 121
  • 203
  • 1
    Have you looked at something like: https://github.com/robbiehanson/CocoaHTTPServer I know it's still a client/server relationship but it appears that the built-in Apple adhoc networking api is still private. – JiuJitsuCoder Mar 12 '13 at 15:23
  • I'm unclear on your question. Are you looking for code that allows you to create an adhoc WiFi network between two iOS devices or are you looking for a way for two iOS devices, already connected via WiFi, to perform p2p communications? – rmaddy Mar 12 '13 at 16:21
  • Just learn how internet and BSD sockets work. Use bind() calls. Use STUN servers. Use a lot of sockets. Use Reachability notifications API. Enumerate network interfaces. Bind to concrete ports. Use multicast sends if you wish. IP is wonderful world, but people who learns to code for Apple don't ever get a thing :-( – Brian Cannard Apr 21 '15 at 23:13

5 Answers5

16

iOS 7 adds the Multipeer Connectivity Framework for exactly this purpose.

Pang
  • 9,564
  • 146
  • 81
  • 122
darrinm
  • 9,117
  • 5
  • 34
  • 34
  • working link https://developer.apple.com/library/ios/DOCUMENTATION/MultipeerConnectivity/Reference/MultipeerConnectivityFramework/index.html – sage444 Oct 15 '14 at 08:19
  • 1
    I don't recommend you to use this framework. It is very universal but it is too slow. – user2159978 Jan 09 '15 at 08:31
4

Have you thought of using Apple's GameKit framework? I've used it in the past for some simple communication between devices. It's really simple and can get you out of the gate quickly. This looks like a good tutorial.

Mr Rogers
  • 6,091
  • 2
  • 32
  • 34
  • The problem is this involves them accepting my app can use gamekit, which seems a bit random to the user. – Andrew Mar 12 '13 at 16:16
  • Which part, the name GameKit, the GameKit UI or both? You can roll all your own custom UI and nobody will be the wiser. The `GKPeerPickerController` will simplify your life right out of the box and doesn't look like one is playing a game. However, you can roll your own solution and have your own UI. – Mr Rogers Mar 12 '13 at 17:36
  • I'm currently using GameKit for p2p data transfer in a non-game, and I'm not aware that users were ever prompted to accept or approve this functionality. Bluetooth connections are fairly easy to set up, however, the connections are flaky and the data transmission is slow for more than small bits of data, compared to wi-fi. – arlomedia Dec 02 '14 at 18:29
  • GameKit part for p2p connection is deprecated. Apple recommends to use Multipeer Connectivity Framework but it is too slow – user2159978 Jan 09 '15 at 08:32
4

I think Open Peer is the right solution. It provides real direct peer-to-peer connection between devices without the need of a centralised server. Check out this introductory video.

naeemjawaid
  • 504
  • 3
  • 10
1

You cannot create a wi-fi network programmatically in iOS using current APIs. GameKit offers some APIs to do so over bluetooth however.

If you wish to implement a custom solution using CocoaHTTPServer, be aware that you will still not be able to create a direct wi-fi connection, you will simply be able to connect devices on the same (pre-existing) wi-fi network.

Ad-hoc peer to peer Wi-Fi (such as 802.11s) in iOS is still a few years off. Maybe iOSX ;)

cleverbit
  • 5,514
  • 5
  • 28
  • 38
  • The [documentation](http://developer.apple.com/library/ios/#documentation/GameKit/Reference/GKSession_Class/Reference/Reference.html) says: A GKSession object provides the ability to discover and connect to nearby iOS devices using Bluetooth or Wi-fi. – Mr Rogers Mar 12 '13 at 17:39
  • Only bluetooth is used for direct peer-to-peer connections. Wi-fi is used for Bonjour over LAN. – cleverbit Mar 22 '13 at 13:47
  • GKSession is deprecated in iOS 7 – user2159978 Jan 09 '15 at 09:24
1

iOS supports the Multipeer Connectivity framework which enables iOS devices to talk to each other over Bluetooth, infrastructure (with a router) WiFi, or P2P.

It does not, however, provide a way to explicitly use P2P. There is a layer of abstraction away from how any of a device's peers (other iOS devices) are connected, and it does not currently allow for non-iOS devices to be connected.

JuJoDi
  • 14,627
  • 23
  • 80
  • 126