iOS devices as web server [closed]
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this questionI saw there are several apps on App Store that allow other computers开发者_JAVA百科 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.
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
You can use GCDWebServer
It's a modern web server for iOS and MacOS based on grand central dispatch.
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:
- 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 toNSHomeDirectory()
. - As of now the MongooseDaemon library contains warnings about deprecated methods used within the Objective-C wrapper.
- CocoaHTTPServer is aware of things like Bonjour or WebDav whereas Mongoose just delivers the basics.
- CocoaHTTPServer comes with many examples that range from simple HTTP servers, passwd, SSL/TLS or WebDav HTTP server.
- CocoaHTTPServer works with GCD to enable multithreading.
MongooseDaemon is also a good choice.
https://github.com/face/MongooseDaemon
精彩评论