import java.io.*;
import java.net.*;public class ChatServer { public static void main(String[] args) {
boolean started = false;
Socket s = null;
ServerSocket ss = null;
DataInputStream dis = null;
try {
ss = new ServerSocket(8888);
}catch(IOException e){
e.printStackTrace();
}
try{
started = true;
while(started){
boolean bconncted = false;
s = ss.accept();
System.out.println("a Client connected~");
bconncted = true;
dis = new DataInputStream(s.getInputStream());
while(bconncted){
String str = dis.readUTF(); System.out.println(str);
}
//dis.close();
}
} catch(EOFException e){
System.out.println("Client closed!");
} catch (IOException e) {
e.printStackTrace();
} finally{
try{
if (dis != null) dis.close();
if (s != null) s.close();
} catch(IOException e1){
e1.printStackTrace();
}
}
}
}