java Swing写的一个小Demo
  Server
  import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.io.PrintWriter;
  import java.net.ServerSocket;
  import java.net.Socket;
  import java.util.ArrayList;
  import java.util.List;
  public class Server {
  static Boolean start = true;
  List<Client> clients = new ArrayList<Client>();
  public static void main(String[] args) {
  new Server().start();
  }
  public void start() {
  Socket s = null;
  ServerSocket serverSocket = null;
  try {
  serverSocket = new ServerSocket(8888);
  while (start) {
  s = serverSocket.accept();
  Client client = new Client(s);
  new Thread(client).start();
  clients.add(client);
  }
  } catch (IOException e) {
  e.printStackTrace();
  } finally {
  if (serverSocket != null) {
  try {
  serverSocket.close();
  } catch (IOException e) {
  e.printStackTrace();
  }
  }
  }
  }
  class Client implements Runnable {
  private Socket socket;
  private BufferedReader br;
  private PrintWriter pWriter;
  private String mes;
  public Client(Socket socket) {
  this.socket = socket;
  try {
  this.br = new BufferedReader(new InputStreamReader(
  socket.getInputStream()));
  this.pWriter = new PrintWriter(socket.getOutputStream(),true);
  } catch (IOException e) {
  e.printStackTrace();
  }
  }
  @Override
  public void run() {
  try{
  while (start) {
  while((mes=br.readLine())!=null){
  System.out.println(mes);
  for (int i = 0; i < clients.size(); i++) {
  if(!this.equals(clients.get(i)))
  clients.get(i).pWriter.println(mes);
  }
  }
  }
  }catch(Exception e){
  e.printStackTrace();
  }finally{
  try {
  if (br!=null) {
  br.close();
  }
  if(socket!=null){
  socket.close();
  }
  if(this!=null){
  clients.remove(this);
  }
  } catch (IOException e) {
  e.printStackTrace();
  }
  }
  }
  }
  }