import java.io.*;
import java.net.*;
public class ChatServer {
public static void main(String[] args) {
boolean started =false;
ServerSocket ss =null;
Socket s=null;
try {
ss = new ServerSocket(8888);
}catch (IOException e) {
e.printStackTrace();
}
try{
started =true;
while(started) {
boolean bConnected =false;
s = ss.accept();
System.out.println("a client connected!");
bConnected = true;
DataInputStream dis = new DataInputStream(s.getInputStream());
while(bConnected){
String str = dis.readUTF();
System.out.println(str);
}
dis.close();
}
} catch (IOException e) {
try {
s.close();
System.out.println("客户端已经离开");
} catch (IOException e1) {
e1.printStackTrace();
}
// e.printStackTrace();
}
}
}