茄子 快牙 什么闪传 的零流量分享原理解析
来源:互联网 发布:备份软件注册表 编辑:程序博客网 时间:2024/06/10 06:18
因为要做零流量分享 ,所有首先你得了解其原理。 一台手机 开启了热点 另一台手机一扫对方二维码 就可以下载对方手机上的应用了。 不需要你得手机有 移动网络,前提是
你连上对方手机开启的热点。
现在 说说大概的原理
安装了茄子或者快牙的手机 当进入零流量分享界面时 会开启热点 毋庸置疑。 其实在后台 : 茄子是 2999端口 快牙是 7989 端口。
ServerSocket = new ServerSocket ( 2999 ); 这是茄子的 。
ServerSocket = new ServerSocket (7989) ; 这是快牙的 。
监听到请求怎么办? 看下面代码:
System.out.println(filePath + " requested.");
outstream.println("HTTP/1.1 200 OK");
outstream.println("MIME-version:1.0");
// outstream.println("Content_Type:text/html");
outstream.println("Content-Type:application/octet-stream");
int len = (int) file.length();
// outstream.println("Location:" + filePath);
outstream.println("Content-Length:" + len);
Log.d(TAG, "len: " + len);
outstream.println("Connection:close");
// outstream.println("Accept-Ranges:bytes");
outstream.println("");
sendPPt(outstream, filePath);
// outstream.println("");
outstream.flush();
这是接到请求 后处理请求 , 把 自己的 应用发给 对方 用的是 http 协议 ,因为 对方使用的是 浏览器下载。
完整代码就不上了,下面给出更详细的代码:
/**
* 模拟HTTP 响应发送给客户端
*
* @param mServer
* @param client
* @param filePath
* @param inline
* @return
*/
public static boolean HandleRequest(MyServerSocket mServer, Socket client,
String filePath, String inline) {
String destIP = client.getInetAddress().toString(); // 瀹㈡埛鏈篒P鍦板潃
int destport = client.getPort(); // 瀹㈡埛鏈虹鍙e彿
PrintStream outstream = null;
try {
outstream = new PrintStream(client.getOutputStream());
} catch (IOException e) {
e.printStackTrace();
}
Log.d(TAG, "ip:" + destIP + " port:" + destport);
try {
System.out.println("Received:" + inline);
if (inline == null)
return false;
mServer.setKeyAndValue(inline);
if (IsgetRequest(inline)) { // 濡傛灉鏄疓ET璇锋眰
File file = new File(filePath);
if (file.exists()) { // 鑻ユ枃浠跺瓨鍦紝鍒欏皢鏂囦欢閫佺粰Web娴忚鍣�
outstream.print("HTTP/1.1 200 OK\r\n");
outstream.print("MIME-version:1.0\r\n");
// outstream.println("Content_Type:text/html");
// outstream.print("Accept-ranges:bytes\r\n");
outstream
.print("Content-Type:application/octet-stream\r\n");
// outstream.println("Server: Sunpache 1.0");
// outstream
// .println("Last-Modified: Mon, 11 Jan 2013 13:23:42 GMT");
long len = file.length();
outstream.print("Content-Length:" + len + "\r\n");
outstream.print("Connection:Close\r\n");
outstream
.print("Content-Disposition:attachment;filename=pengpengtang.apk\r\n");
// outstream.println("Connection" + "Keep-Alive");
Log.d(TAG, "len: " + len);
outstream.print("\r\n");
// 响应体
if (sendPPt(outstream, filePath, len)) {
Log.d(TAG, "send success");
}
outstream.flush();
return true;
} else { // 鏂囦欢涓嶅瓨鍦ㄦ椂
String notfound = "<html><head><title>Not Found</title></head><body><h1>Error 404-file not found</h1></body></html>";
outstream.print("HTTP/1.1 404 no found\r\n");
outstream.print("Content-Type:text/html\r\n");
outstream.print("Content-Length:" + (notfound.length() + 2)
+ "\r\n");
outstream.print("\r\n");
outstream.print(notfound + "\r\n");
outstream.flush();
return true;
}
} else
return false;
} catch (Exception exception) {
exception.printStackTrace();
}
return false;
}
- 茄子 快牙 什么闪传 的零流量分享原理解析
- 茄子快传使用测评
- 仿茄子快传的一款文件传输应用
- 仿茄子快传应用源码下载
- Android如何实现茄子快传
- Android仿茄子快传-实现面对面快传功能
- Android仿茄子快传-实现面对面快传功能
- 从”茄子快传”看应用程序如何获取手机已安装程序的apk文件
- 茄子快传和腾讯全民Wifi配合使用
- 如何打造 茄子快传 这样一款文件传输应用
- 感觉流量跑得快?那么有什么控制流量的方法呢?
- 解析android 流量监测的实现原理
- 解析android 流量监测的实现原理
- 快牙:不耗费流量的手机文件传输应用
- 仿茄子快传——获取安装应用列表信息
- 关于茄子的故事
- 流量统计的原理
- 流量压缩软件的流量统计原理
- modify is ambiguous in Mapped Statements collection (try using the full name including the namespace
- 如何根据事物代码查找相应BAPI
- 配置iSCSI磁盘
- JavaWeb -- Jsp中的 EL表达式
- PHP+Mysql+jQuery实现文件下载次数统计
- 茄子 快牙 什么闪传 的零流量分享原理解析
- Top 10 Algorithms for Coding Interview
- 并发编程之Executors及其子类
- FullCalendar日历插件说明文档
- WebApp之Meta标签
- Mysql 体系结构系列之十三
- jQuery获取Radio选择的Value值
- HTML5移动WEB开发
- 关于接口回调