📄 connection.java
字号:
package proxy;
import java.net.Socket;
import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;
public class Connection extends Thread {
protected ProxyServer ProxyServerHandle = null;
protected Socket client;
protected Service service;
private boolean isEnd = false;
volatile boolean stop = false; //是否请求停止
public Connection(ProxyServer ProxyServer, Socket client, Service service) throws Exception{
super("Server Connection:" + client.getInetAddress().getHostAddress()
+ ":" + client.getPort());
this.client = client;
this.service = service;
this.ProxyServerHandle = ProxyServer;
}
/**
* 停止连接
***/
public void pleaseStop() {
this.stop = true;
try{
if (isEnd){
client.getInputStream().close();
client.getOutputStream().close();
client.close();
this.ProxyServerHandle.endConnection(this);
}
}catch (IOException e) {}
}
/**
* 停止连接
***/
public void immedStop() {
this.stop = true;
try{
client.getInputStream().close();
client.getOutputStream().close();
client.close();
}catch (IOException e) {}
}
public void run(){
while(!this.stop){
InputStream in = null;
OutputStream out = null;
try {
service.serve(client);
//判断SOCKET是否断开
if (client.isClosed()){
ProxyServerHandle.endConnection(this);
break;
}
} catch (Exception e) {
Logs.log(e);
}
try{
Thread.sleep(50);
}catch(Exception e){}
isEnd = true;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -