-
大小: 108KB文件类型: .zip金币: 1下载: 0 次发布日期: 2021-06-11
- 语言: Java
- 标签: MediaPlayer Http Get Proxy
资源简介
如何实现一个简单的代理服务器(仅支持Http Get),与Android的MediaPlayer结合,从而可以扩展出“播放 反盗链的媒体文件”,“边播放边保存”的功能。
代码片段和文件信息
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.UnknownHostException;
public class HttpGetProxy {
final private String LOCAL_IP_ADDRESS = “127.0.0.1“;
final private int HTTP_PORT = 80;
private ServerSocket localServer = null;
private Socket localSocket = null;
private Socket remoteSocket = null;
private String remoteIPAddress;
private InputStream in_remoteSocket;
private OutputStream out_remoteSocket;
private InputStream in_localSocket;
private OutputStream out_localSocket;
private interface onfinishListener {
void onfinishListener();
}
public HttpGetProxy(int localport) {
// --------建立代理中转服务器-----------//
try {
localServer = new ServerSocket(localport 1
InetAddress.getByName(LOCAL_IP_ADDRESS));
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* 结束时,清除所有资源
*/
private onfinishListener finishListener =new onfinishListener(){
@Override
public void onfinishListener() {
System.out.println(“..........release all..........“);
//Log.e(“---->““..........release all..........“);
try {
in_localSocket.close();
out_remoteSocket.close();
in_remoteSocket.close();
out_localSocket.close();
localSocket.close();
remoteSocket.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
public void startProxy(String remoteIpAddr) throws IOException {
remoteIPAddress = remoteIpAddr;
SocketAddress address = new InetSocketAddress(remoteIPAddressHTTP_PORT);
// --------连接目标服务器---------//
remoteSocket = new Socket();
remoteSocket.connect(address);
System.out.println(“..........remote Server connected..........“);
//Log.e(“---->““..........remote Server connected..........“);
in_remoteSocket = remoteSocket.getInputStream();
out_remoteSocket = remoteSocket.getOutputStream();
System.out.println(“..........init remote Server I/O..........“);
/**
* 接收本地request,并转发到远程服务器
*/
new Thread() {
public void run() {
int bytes_read;
byte[] local_request = new byte[5120];
try {
// 本地Socket
localSocket = localServer.accept();
System.out.println(“..........localSocket connected..........“);
// Log.e(“---->““..........localSocket connected..........“);
in_localSocket = localSocket.getInputStream();
out_localSocket = localSocket.getOutputStream();
System.out.println(“..........init local Socket I/O..........“);
// Log.e(“---->““..........local start to receive..........“);
String buffer = ““;
while ((byt
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2012-02-06 10:24 HttpGetProxy\
目录 0 2012-02-06 10:27 HttpGetProxy\HttpGetProxy\
文件 232 2012-02-06 10:26 HttpGetProxy\HttpGetProxy\.classpath
文件 388 2012-02-06 10:26 HttpGetProxy\HttpGetProxy\.project
目录 0 2012-02-06 10:50 HttpGetProxy\HttpGetProxy\.settings\
文件 88 2012-02-06 10:50 HttpGetProxy\HttpGetProxy\.settings\org.eclipse.core.resources.prefs
文件 629 2012-02-06 10:27 HttpGetProxy\HttpGetProxy\.settings\org.eclipse.jdt.core.prefs
目录 0 2012-02-06 11:50 HttpGetProxy\HttpGetProxy\bin\
文件 1308 2012-02-06 11:45 HttpGetProxy\HttpGetProxy\bin\HttpGetProxy$1.class
文件 2897 2012-02-06 11:45 HttpGetProxy\HttpGetProxy\bin\HttpGetProxy$2.class
文件 1298 2012-02-06 11:45 HttpGetProxy\HttpGetProxy\bin\HttpGetProxy$3.class
文件 223 2012-02-06 11:45 HttpGetProxy\HttpGetProxy\bin\HttpGetProxy$on
文件 3535 2012-02-06 11:45 HttpGetProxy\HttpGetProxy\bin\HttpGetProxy.class
文件 728 2012-02-06 11:50 HttpGetProxy\HttpGetProxy\bin\testHttpGetProxyForJ2SE.class
目录 0 2012-02-06 11:59 HttpGetProxy\HttpGetProxy\src\
文件 5023 2012-02-06 11:26 HttpGetProxy\HttpGetProxy\src\HttpGetProxy.java
文件 582 2012-02-06 11:59 HttpGetProxy\HttpGetProxy\src\testHttpGetProxyForJ2SE.java
目录 0 2012-02-06 13:17 HttpGetProxy\musicpla
文件 288 2012-02-06 10:38 HttpGetProxy\musicpla
文件 847 2011-05-09 09:15 HttpGetProxy\musicpla
目录 0 2012-02-06 09:02 HttpGetProxy\musicpla
文件 170 2012-02-06 09:02 HttpGetProxy\musicpla
文件 629 2011-05-09 09:29 HttpGetProxy\musicpla
文件 756 2011-05-09 13:47 HttpGetProxy\musicpla
目录 0 2011-05-09 09:14 HttpGetProxy\musicpla
目录 0 2012-02-06 09:02 HttpGetProxy\musicpla
目录 0 2012-02-06 13:17 HttpGetProxy\musicpla
文件 13436 2012-02-06 09:02 HttpGetProxy\musicpla
文件 13032 2012-02-06 13:17 HttpGetProxy\musicpla
目录 0 2012-02-06 13:17 HttpGetProxy\musicpla
目录 0 2012-02-06 13:17 HttpGetProxy\musicpla
............此处省略64个文件信息
相关资源
-
玩转 Android MediaPla
yer之视频预加载 - Android 天气预报加widget源码
- Android_HttpClient_jar包
- AsyncHttpClient所需的jar包
- httpclient-android-4.3.5.1.jar
- android jni使用curl进行http请求和文件
- Android应用底部导航栏(选项卡)Dem
- C#通过SOAP使用HttpWebRequest调用带有身份
- okhttp3(包含http-3.9.0.jar和okio1.13.0.ja
- java通过HTTP调用接口Get请求和Post请求
- tomcat httpHeaderSecurity.jar
- httpclient-4.3.6.jar架包
- MyBatis-Generator 自动生成Lombok标签 不生
- httpclientjar包
- com.sun.net.httpserver.jar
- java:静态web服务器实现http
- httpclient需要的jar包,合订版httclient
- 解决Android下getifaddrs和freeifaddrs undef
- 根据银行卡号 获取银行名称
- java写的目前最完美的http代理程序
- httpmime-4.1.1.jar
- httpservletrequest的jar包
- android httpclient
- Java实现Web服务器和客户端
- Android 使用OkHttp3报错处理
- java 调用okHttp3进行代码测试SpringBoot项
- httpservlet的jar包,修复httpservlet报错
- org.apache.commons.httpclient相关资源包
- httpclient-3.1
- httpclient-4.3.6
评论
共有 条评论