package ;
import ;
import ;
import ;
import ;
import ;
import ;
public class Server {
public static final int PORT = 12345;
public static void main(String[] args) {
("服务器启动...\n");
Server server = new Server();
();
}
public void init() {
try {
ServerSocket serverSocket = new ServerSocket(PORT);
while (true) {
Socket client = ();
new HandlerThread(client);
}
} catch (Exception e) {
("服务器异常: " + ());
}
}
private class HandlerThread implements Runnable {
private Socket socket;
public HandlerThread(Socket client) {
socket = client;
new Thread(this).start();
}
public void run() {
try {
DataInputStream input = new DataInputStream(());
String clientInputStr = ();
("客户端发过来的内容:" + clientInputStr);
DataOutputStream out = new DataOutputStream(());
("请输入:\t");
String s = new BufferedReader(new InputStreamReader()).readLine();
(s);
();
();
} catch (Exception e) {
("服务器 run 异常: " + ());
} finally {
if (socket != null) {
try {
();
} catch (Exception e) {
socket = null;
("服务端 finally 异常:" + ());
}
}
}
}
}
}