76 lines
1.5 KiB
Java
76 lines
1.5 KiB
Java
package org.kne.cloud.network.klalb;
|
|
|
|
import java.io.BufferedInputStream;
|
|
import java.io.BufferedOutputStream;
|
|
import java.io.DataInputStream;
|
|
import java.io.DataOutputStream;
|
|
import java.io.IOException;
|
|
import java.net.Socket;
|
|
import java.net.SocketException;
|
|
import java.net.UnknownHostException;
|
|
import java.util.zip.GZIPInputStream;
|
|
import java.util.zip.GZIPOutputStream;
|
|
|
|
public class TCPConnection {
|
|
|
|
|
|
|
|
protected Socket connect;
|
|
protected DataInputStream din;
|
|
protected DataOutputStream dout;
|
|
|
|
public DataInputStream getDin() {
|
|
return din;
|
|
}
|
|
|
|
public DataOutputStream getDout() {
|
|
return dout;
|
|
}
|
|
|
|
public void close() {
|
|
try {
|
|
if (din != null)
|
|
din.close();
|
|
} catch (IOException e1) {
|
|
// TODO 自动生成的 catch 块
|
|
e1.printStackTrace();
|
|
}
|
|
try {
|
|
if (dout != null)
|
|
dout.close();
|
|
} catch (IOException e1) {
|
|
// TODO 自动生成的 catch 块
|
|
e1.printStackTrace();
|
|
}
|
|
try {
|
|
if (connect != null)
|
|
connect.close();
|
|
} catch (IOException e) {
|
|
// TODO 自动生成的 catch 块
|
|
e.printStackTrace();
|
|
}
|
|
connect = null;
|
|
}
|
|
|
|
public TCPConnection( Socket soc) throws IOException {
|
|
connect = soc;
|
|
initIO();
|
|
}
|
|
|
|
|
|
|
|
protected void initIO() throws IOException {
|
|
dout = new DataOutputStream( connect.getOutputStream());
|
|
din = new DataInputStream(connect.getInputStream());
|
|
}
|
|
|
|
public boolean isOpen() {
|
|
if(connect==null) {
|
|
return false;
|
|
}
|
|
return !connect.isClosed();
|
|
}
|
|
|
|
|
|
}
|