合并IO线程管理类
This commit is contained in:
@@ -9,11 +9,11 @@ import java.util.UUID;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
public class KLALBServer {
|
||||
WeakHashMap<UUID, KLALBServerProtocol> whm=new WeakHashMap<>();
|
||||
WeakHashMap<UUID, IOThreadManager> whm=new WeakHashMap<>();
|
||||
public KLALBServer(int port) throws IOException {
|
||||
TCPListener tcpl=new TCPListener(port);
|
||||
tcpl.setCon((s)->{
|
||||
try {
|
||||
try {
|
||||
//s.setSoTimeout(10000);
|
||||
DataInputStream din=new DataInputStream(s.getInputStream());
|
||||
int val=din.readShort()&0xffff;
|
||||
@@ -22,12 +22,12 @@ public class KLALBServer {
|
||||
}
|
||||
UUID uid=new UUID(din.readLong(),din.readLong());
|
||||
System.out.println(uid);
|
||||
KLALBServerProtocol nx = null;
|
||||
IOThreadManager nx = null;
|
||||
if(whm.containsKey(uid)) {
|
||||
nx=whm.get(uid);
|
||||
}else {
|
||||
nx=new KLALBServerProtocol();
|
||||
Socket soc=new Socket("192.168.1.233",3389);
|
||||
nx=new IOThreadManager();
|
||||
Socket soc=new Socket("192.168.1.233",8444);
|
||||
nx.setOut(soc.getOutputStream());
|
||||
nx.setIn(soc.getInputStream());
|
||||
nx.startLocal();
|
||||
@@ -35,6 +35,11 @@ public class KLALBServer {
|
||||
|
||||
}
|
||||
nx.handleSocket(new TCPConnection(null,s));
|
||||
int n=nx.getTcps().size();
|
||||
if(n<=0) {
|
||||
nx.closeALL();
|
||||
System.out.println("连接已关闭");
|
||||
}
|
||||
}catch(ConnectException e) {
|
||||
System.out.println("连接本地服务失败,请检查你的服务程序");
|
||||
}catch(IOException e) {
|
||||
|
||||
Reference in New Issue
Block a user