iPhone HTTP 服务器
有人可以给我简单的代码来帮助我为 iPhone 创建 HTTP 服务器吗?一些简单且有大量文档的东西将不胜感激。你有什么请分享。
Can someone give me simple code to help with creating an HTTP server for the iPhone. Something simple with much documentation would be appreciated. Anything you have please share.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
有来自Apple和开源社区(例如cocoahttpserver TouchHTTPD)的示例代码。
这是一个摘要博客
There are sample codes from Apple and open source community such as cocoahttpserver TouchHTTPD.
Here's a summary blog
iPhone 的另一个开源 HTTP 服务器是轻量级 GCDWebServer,它构建在 Grand Central Dispatch 之上。它只有几个源代码文件,并提供简单且可扩展的 API。
Another open-source HTTP server for iPhone is the lightweight GCDWebServer which is built on top of Grand Central Dispatch. It's only a few source code files and offers a simple and extensible API.
如果您不熟悉网络编程,最好的选择是首先阅读 Beej 网络编程指南 并然后在查看源代码之前阅读 HTTP 1.1 规范(因为你应该在开始研究实现之前先了解协议)。
简单的 Google 搜索就出现了 cocoahttpserver 和 iSpit。否则,您可以下载 Apache 并查看其源代码,但这并不完全是一个简单的实现。
If you're unfamiliar with network programming your best bet is to first read Beej's Guide to Network Programming and then read the HTTP 1.1 spec before you look at source code (as you should have an understanding of the protocol before you start looking at implementations).
A simple Google search turned up cocoahttpserver and iSpit. Otherwise, you could download Apache and look at its source code, but that's not exactly a simple implementation.
可以在 iPhone/iOS 上运行简单的文件服务器。
我能够成功地使用这个方法。以下是创建一个基于 http 协议的简单文件服务器的步骤。
1. 安装 iOS 版 TestFlight 应用程序
2. 从 Apple 商店安装 iSH 应用程序或从其网站加载该应用程序,因为根据您所在的国家/地区,该应用程序可能无法在商店中使用。我于 2020 年 5 月在印度尝试过,但该应用程序在商店中不可用。所以我从他们的网站上加载了它。
3.通过iSH应用程序,可以访问iPhone的linux内核。我确实使用了 python 中的一个简单的 http 服务器模块,并在 Linux shell 上执行它。
4. 在 iPhone 上运行基于 python 的服务器的命令:
Python -m http.server 8080
5. 使用在您连接的网络中分配给 iPhone 的本地 IP 访问文件服务器。这意味着,如果 iPhone 连接到 WiFi SSID,根据路由器是否配置为使用基于 MAC 地址的静态 IP 地址分配或使用 DHCP 协议,您的 iPhone 将拥有由路由器分配的内部 IP。
6. 访问文件服务器的命令:
http://192.168.1.3:8080 - 根据 iPhone 的 IP 地址和端口修改地址在 iPhone 上运行的服务器被配置为使用。将其粘贴到浏览器中 - 人们应该能够看到服务器运行目录中列出的文件。
希望这足够清楚,可以使用 python 中的 http.server 模块在 iPhone 上运行一个简单的基于 http 的文件服务器,底层内核的linux shell,使用iSH。
It is possible to run a simple file server on iPhone/iOS.
I was able to use this method successfully. Here are the steps to create a simple file server which works on http protocol.
1. Install TestFlight app for iOS
2. Install iSH app from the Apple store or side load it from their website, as this app might not be available in the store depending on your country. I tried it from india in May 2020, and the app was not available in the store. So i did side load it from their website.
3. With iSH app, one has access to linux kernel of the iPhone. I did use a simple http server module from python and executed it on the linux shell.
4. Command to run the python based server on iPhone :
Python -m http.server 8080
5. Access the file server using the local ip that’s assigned to the iPhone in the network you are connected to. That means, if iPhone is connected to a WiFi SSID, depending on whether the router is configured to use static IP address assignment based on MAC address or using DHCP protocol, your iPhone will have an internal IP assigned by the router.
6. Command to access the file server :
http://192.168.1.3:8080 - modify the address depending on IP address of the iPhone and the port that server running on iPhone is configured to use. Paste this in a browser - one should be able to see the files listed in the directory where the server is running in.
Hope this was clear enough, for running a simple http based file server on iPhone using http.server module in python, over linux shell of the underlying kernel, using iSH.