iOS 设备作为网络服务器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6804650/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
iOS devices as web server
提问by user523234
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?
我看到 App Store 上有几个应用程序允许其他计算机与 iPhone/iPad 设备建立 http 连接以传输文件。似乎在 iOS 设备上运行了一个 Web 服务。只是好奇它是如何完成的/使用了什么类?
Thanks.
谢谢。
采纳答案by hotpaw2
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:
只需要显示设备的IP地址,在iOS设备上运行的应用程序中打开一个socket监听,并实现http协议。有几个 3rd 方库可以为您完成大部分繁重的工作:
CocoaHTTPServeror iPhoneHTTPServer3, or SimpleWebSocketServer, or MultithreadedHTTPServer3
CocoaHTTPServer或 iPhoneHTTPServer3,或 SimpleWebSocketServer,或 MultithreadedHTTPServer3
回答by loretoparisi
You can use GCDWebServer
您可以使用GCDWebServer
It's a modern web server for iOS and MacOS based on grand central dispatch.
它是基于盛大中央调度的适用于 iOS 和 MacOS 的现代 Web 服务器。
回答by Patrik
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: CocoaHTTPServerand MongooseDaemon.
就像之前回答的那样,最好的选择是为此使用 3rd 方库。主要有两个库来完成这项工作:CocoaHTTPServer和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.
它们都有一个 Objective-C API,但 MongooseDaemon 只是用普通 c 编写的 Mongoose HTTP 服务器的包装器,而 CocoaHTTPServer 完全用 Objective-C 编写。
We decided to go with CocoaHTTPServer because of a few simple reasons:
我们决定使用 CocoaHTTPServer 有几个简单的原因:
- 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.
- 即使是最简单的属性,比如为 HTTP 服务器设置文档目录,在 MongooseDaemon 中也不存在。您必须更改
#define
包含的源文件中的 a 才能将其从指向NSHomeDirectory()
. - 截至目前,MongooseDaemon 库包含有关在 Objective-C 包装器中使用的已弃用方法的警告。
- CocoaHTTPServer 知道 Bonjour 或 WebDav 之类的东西,而 Mongoose 只提供基础知识。
- CocoaHTTPServer 附带了许多示例,包括简单的 HTTP 服务器、passwd、SSL/TLS 或 WebDav HTTP 服务器。
- CocoaHTTPServer 与 GCD 配合使用以启用多线程。
回答by Vanguarder
MongooseDaemon is also a good choice.
MongooseDaemon 也是一个不错的选择。