over air文件传输功能

来源:互联网 发布:免费网站模板源码下载 编辑:程序博客网 时间:2024/05/02 02:54

Q:

越来越多的程序提供in-app的无线连接存在下的局域网内的文件传输功能,最多见的就是通过一个web page,上传控件来上传文件;其实对于一直使用linux内核的人稍微懂一些浏览器/webserver知识的应该不是困难的事情 。

copy from/to over air:::很cool的词over air

 

In applications like 'simple pdf reader' you flick a switch in the app and are provided with an IP Address and port number. You then enter these details into a computer browser on the same wireless network and can then get to a web page hosted by the device. This real world example allows copy of pdf files to and from that device's app

Sample实例:

Host Your Website from Apple iPad with Nginxfor iOS

A great news for iPad users.From now if you want to host your website from your iPad it’s possible.In other words you can develop PHP web apps on your Apple iPad.Jordan (aka Greysyntax) has compiled and rebuild Nginx with zlib (lightweight but powerful webserver for Linux & Unix system) to run on Apple iOS.
 

The Nginx package for iOS comes with SSL and gzip support enough to power up small website. An important point to be noted here is that Apple iPad doesn’t have horsepower to run full fledged website or PHP web app, but this is actually the real excitement to see what this magical device can show its magic in here.

==========================

A Simple HTTP Server

 →Download Xcode Project::: under ios sample file folder

What it is
 
The Xcode project of a simple web server. It demonstrates how to use NSFileHandle, NSSocketPort, and Cocoa notifications to write a simple server application. Core Foundation functions are used to create and parse HTTP messages. It also shows how to replace NSSocketPort with native Unix calls.

What it does
 
SimpleHTTPServer listens to port 50000, uses the path of the request-URL to construct a new URL by inserting "http://" at the beginning, loads this new URL and renders its contents to a PDF file. The PDF file is returned to the client.......  
renders its contents to a PDF file........ just as reading PDF?

How to use it
 
With SimpleHTTPServer runnning, open Safari 2.0 and type, for example, "http://localhost:50000/www.apple.com". Both the IP address of the connecting client as well as the path of the request-URL are picked up by SimpleHTTPServer, and the corresponding page is loaded into a web view. Once the web page is converted to PDF, the PDF data is sent back to Safari where it is displayed inside the browser window.

 

==========================

CocoaHTTPServer

https://github.com/robbiehanson/CocoaHTTPServer/wiki

CocoaHTTPServer is a small, lightweight, embeddable HTTP server for Mac OS X or iOS applications.

Sometimes developers need an embedded HTTP server in their app. Perhaps it's a server application with remote monitoring. Or perhaps it's a desktop application using HTTP for the communication backend. Or perhaps it's an iOS app providing over-the-air access to documents. Whatever your reason, CocoaHTTPServer can get the job done. It provides:

  • Built in support for bonjour broadcasting
  • IPv4 and IPv6 support
  • Asynchronous networking using GCD and standard sockets
  • Password protection support
  • SSL/TLS encryption support
  • Extremely FAST and memory efficient
  • Extremely scalable (built entirely upon GCD)
  • Heavily commented code
  • Very easily extensible
  • WebDAV is supported too!

接下来就是研究web page,以及文件写入了吧

 

 

CocoaHTTPServer实现multipart/form-data上传表单

 

source code:WebServer

http://github/willonboy

另附上CocoaHTTPServer官方示例工程source code:CocoaHTTPServer(官方示例)

CocoaHTTPServer真的很棒, 不仅支持get, post, put, delete, header等 还支持Redirect, Authentication Request, websocket, 简单的动态网页(HTTPDynamicFileResponse) !

而且里面的代码很值得去深入研究!

 

让iphone成为一个webserver然后上传文件,然后阅读。 WebDAV服务器是基于CocoaHTTPServer的

 

===============

http://sourceforge.net/scm/?type=svn&group_id=253777&source=navbar

MP4视频,图片和PDF文件都可以正常打开,下图就是打开PDF文件的截图。


程序代码可以从http://sourceforge.net/projects/openfilebrowser/下载到,sample不支持中文,这样就需要采用最新的代码看看了

所谓的 bonjour地址 :类似于XXX.hostName:8090,windows下称为bois name/NT name

Bonjour Service Published: domain(local.) type(_http._tcp.) name(admin’s MacBook



其他:
在app store里也有类似程序在出售,我自己就买过2,1个iFile要钱的,还有一个Fileslite免费的。由于iPhone不能直接当作USB存储设备,才有了这类程序的诞生。但大多原理都一样,让iphone成为一个webserver然后上传文件,然后阅读。 WebDAV服务器是基于CocoaHTTPServer的,一款开元的代码,可以从GoogleCode上找到:http://code.google.com/p/cocoahttpserver/

增加提示说明使用itune也可以文件共享


原创粉丝点击