Wednesday 20 January 2016

iOS Swift- Sending Photos peer-to-peer using NSNetServices and NSStream

Recently I have been exploring NSNetServices and NSStream to send data between two iOS devices. The easiest way to do it is using Apple Multipeer Connectivity. However, I wanted to explore NSNetService and NSStream. There are few reasons why I used those APIs. First this has helped me to understand the complexity and issues while implementing networking Apps at a lower level. Second the concepts are useful while connecting the iOS devices with low Bluetooth energy devices.

In the sample App two iOS devices can send photos to each other. You can download my sample App from here.  Please click on the video to see the demo of the App.



I have used NSNetService to publish and browse photo sharing service. NSNetService can be used to publish the service and NSNetServiceBrowser can be used to browse published services. Once service is found and resolved then NSOutputStream is used to send photos and NSInputStream is used to receive photos.

I have used following resources to implement the sample App:
NSNetServices and CFNetworking programming guide
WiTap Sample
Stream Programming Guide

I plan to write more about the topic and update my code as I get a better understanding of the topic. Please let me know if you find any problems in the code.


2 comments:

  1. I'm doing the same thing, how's it going? I am a pretty solid mobile developer, working on a side project unrelated to my professional dev work. I have a mostly working prototype but was refining it to fit better with the framework that I'm replacing. Nothing like digging one level deeper, huh?

    ReplyDelete
  2. How can i implement this code for multi peer connectivity

    ReplyDelete