I'm trying to create an application that has the ability to transfer large files between iOS devices through what I'll call a "true" peer-to-peer network ie two devices connected directly to each other without an intermediate router / wi-fi network. I've determined I have three high level options:
1) Apple's Multipeer Connectivity library, which enables discovery of other nearby devices and also includes the ability to send what Apple coins "Resources" aka files. My prototyping with this revealed this Framework is awful at sending large files (200 MB+). Speeds rarely broke above 200KB/s and were unreliable. The fastest I ever saw this framework get was around 1 MB/s. Other people's experience seem to mirror mine from what I've seen online.
2) NSNetService
's discovery service in addition to it's ability to easily grab NSInputStream
and NSOutputStream
s. Using this in conjunction with the NSNetServices
includePeerToPeer
property allows me to easily and quickly connect to devices in a "true" peer to peer fashion and send data over the network using these streams. This would be great, but dealing with input and output streams is exceptionally complicated because I need to pack header data (incoming file name, size, location, etc) into the stream. I have this working in practice, but I'm uneasy with my implementation and feel as though there is no way I could cover all my bases. In a sense, I very much feel like I'm re-inventing the wheel here.
3) My ideal solution would use NSNetService
's ability to detect and connect to peers as the last solution does, but would implement CocoaAsyncSockets
to handle the actual file transfers, allowing me to use an established library with a proven track record that also lets me get away from the nitty gritty details of using NSInputStream
and NSOutputStream.
The problem I'm having here is that while CocoaAsyncSockets work great when the devices are connected to the same network, they can't connect to each other on a true peer to peer network, presumably because they understandably can't see each other through the normal ethernet interfaces. It appears that the true peer to peer stuff uses Apple's awdl interface, which I've read on the developer forums cannot be used like a normal interface (I've tried specifying that interface when connecting the socket, it doesn't work).
I know this is rather vague, but does anyone have any suggestions for me? One of the developer's on the Apple developer forums mentioned something on a related topic about creating my own sockets from the sockets provided via the NSNetService
when using publishWithOptions:NSNetServiceListenForConnections
, but he didn't provide much information and I can't seem to figure out how that would work.