📄 client.java~3~
字号:
package train.client;
import java.io.*;
import java.net.*;
import train.parameter.*;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: 沈阳化工学院计算机</p>
*
* @author 彭胜勇 胡林
* @version 1.0
*/
public class Client {
Socket skt;
InputStream is;
ObjectInputStream ois;
OutputStream os;
ObjectOutputStream oos;
String host = null;
int port;
public Client(String host, int port) {
this.host = host;
this.port = port;
}
//建立连接
public void connect() {
try {
System.out.println("hhhhhhhhhhhhhhhhhhhhh");
skt = new Socket(host == null ? CommonConstant.localhost : host,
port);
is = skt.getInputStream();
os = skt.getOutputStream();
oos = new ObjectOutputStream(os);
} catch (UnknownHostException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
}
public Object read() {
if (ois == null) {
try {
ois = new ObjectInputStream(is);
} catch (IOException ex) {
ex.printStackTrace();
}
}
try {
return ois.readObject();
} catch (ClassNotFoundException ex1) {
ex1.printStackTrace();
return null;
} catch (IOException ex1) {
ex1.printStackTrace();
return null;
}
}
public void write(Object obj) {
try {
oos.writeObject(obj);
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -