//聊天Server端程序,能过编译 就是运行出错!
import java.net.*;
import java.io.*;
public class ServerChat {
boolean started = false;
ServerSocket ss = null; public static void main(String[] agrs){
new ServerChat().sta();
} public void sta(){
try{
ss = new ServerSocket();
started =true;
}catch(BindException e1){
System.out.println("端口使用中....");
System.exit(0);
}catch(IOException e3){
e3.printStackTrace();
}
try{
while(started){
Socket soc = ss.accept();
new Thread(new Client1(soc)).start();
System.out.println("Clienting! >>");
}
}catch(IOException e){
e.printStackTrace();
System.out.println("Client is close!");
}finally{
try{
ss.close();
}catch(Exception e){
e.printStackTrace();
}
}
}

class Client1 implements Runnable{
private Socket soc = null;
private DataInputStream input1 = null;
boolean tx = false;

public Client1(Socket e){
soc = e;
tx = true;
try{
input1 = new DataInputStream(soc.getInputStream());
}catch(IOException e2){
e2.printStackTrace();
}
}
public void run() {
try{
while(tx){
String tem = input1.readUTF();
System.out.println(tem);
}
}catch(EOFException e){
System.out.println("is closing...");
}catch(IOException e1){
e1.printStackTrace();
}finally{
try{
if(input1 != null)
input1.close();
if(soc != null)
soc.close();
}catch(IOException e1){
e1.printStackTrace();
}
}
}
}
}