iOS devices as web server

61,085

Solution 1

Just display the devices IP address, open a socket for listening in an app running on the iOS device, and implement the http protocol. There are several 3rd party libraries that can do most of the heavy lifting for you:

CocoaHTTPServer or iPhoneHTTPServer3, or SimpleWebSocketServer, or MultithreadedHTTPServer3

Solution 2

You can use GCDWebServer

It's a modern web server for iOS and MacOS based on grand central dispatch.

Solution 3

Like answered before the best choice is to use a 3rd party library for this. There exist mainly two libraries to get the job done: CocoaHTTPServer and MongooseDaemon.

Both of them have an Objective-C API but MongooseDaemon is just a wrapper around the Mongoose HTTP server written in plain c, whereas CocoaHTTPServer is completely written in Objective-C.

We decided to go with CocoaHTTPServer because of a few simple reasons:

  1. Even the simplest property like setting the document directory for the HTTP server does not exist in MongooseDaemon. You have to change a #define in an included source file to be able to change it from the default one, which points to NSHomeDirectory().
  2. As of now the MongooseDaemon library contains warnings about deprecated methods used within the Objective-C wrapper.
  3. CocoaHTTPServer is aware of things like Bonjour or WebDav whereas Mongoose just delivers the basics.
  4. CocoaHTTPServer comes with many examples that range from simple HTTP servers, passwd, SSL/TLS or WebDav HTTP server.
  5. CocoaHTTPServer works with GCD to enable multithreading.

Solution 4

MongooseDaemon is also a good choice.

https://github.com/face/MongooseDaemon

Share:
61,085
user523234
Author by

user523234

Updated on July 09, 2022

Comments

  • user523234
    user523234 almost 2 years

    I saw there are several apps on App Store that allow other computers to make a http connection to the iPhone/iPad devices to transfer files. It seemed like a web service is running on the iOS device. Just curious how is it done /what class was used?

    Thanks.

  • Paul
    Paul over 12 years
    Seems to be a file server. I didn't see anything about callback
  • funroll
    funroll over 9 years
    CocoaHTTPServer hasn't been updated in a year and has lots of stagnant pull requests and issues. GCDWebServer is brand new, with TravisCI and Swift. +1.
  • loretoparisi
    loretoparisi over 9 years
    ...and it's also commonly accepted by the community and big developers, like LG ConnectSDK
  • RollRoll
    RollRoll over 6 years
    wondering if I can only host static .html files or run something dynamic on the "server side" php or whathever.
  • hotpaw2
    hotpaw2 over 6 years
    Sure, but you would have to find or write your dynamic server in Swift (or Obj C) and the server would have to run inside the same process (with the same background permissions) as the iOS app.
  • Odd
    Odd over 4 years
    How is this supposed to be an answer? MongooseDaemon was already mentioned by @Patrik. This must have at max be only a comment.