import java.io.IOException;
import java.net.*;
import java.io.*;
public class ChatServer {
  public static void main(String[]args){
  boolean falg = true;
  ServerSocket ss = null;
  Socket s = null; 
  try {
 ss = new ServerSocket(8888);
  }catch(IOException e){
  e.printStackTrace(); 
  }
while(falg){

   boolean bfalg = false;
   s = ss.accept();
System.out.print("服务器启动了");

      try{
          bfalg = true;
          DataInputStream dis = new DataInputStream(s.getInputStream());
          while(bfalg){
          String str = dis.readUTF();
          System.out.println(str);
          }
          dis.close();
          s.close();
}
}
catch (IOException e) {

e.printStackTrace();
}
  }
  
}

解决方案 »

  1.   

    package com.lzz.test;import java.io.IOException;
    import java.net.*;
    import java.io.*;public class ChatServer {
    public static void main(String[] args) {
    boolean falg = true;
    ServerSocket ss = null;
    Socket s = null;
    try {
    ss = new ServerSocket(8888);
    } catch (IOException e) {
    e.printStackTrace();
    }
    while (falg) { boolean bfalg = false;
    s = ss.accept();
    System.out.print("服务器启动了"); try {
    bfalg = true;
    DataInputStream dis = new DataInputStream(s.getInputStream());
    while (bfalg) {
    String str = dis.readUTF();
    System.out.println(str);
    }
    dis.close();
    s.close();
    } catch (IOException e) { e.printStackTrace();
    }
    } }
    }正确的应该是这样的,仔细对照着看吧
      

  2.   

    看看吧,一处多一个,最后少一个:
    import java.net.*;
    import java.io.*;public class Test {
    public static void main(String[] args){
      boolean falg = true;
      ServerSocket ss = null;
      Socket s = null; 
      try {
      ss = new ServerSocket(8888);
      }catch(IOException e){
      e.printStackTrace(); 
      }
      while(falg){
       boolean bfalg = false;
       try {
    s = ss.accept();
    } catch (IOException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
    }
       System.out.print("服务器启动了");    try{
              bfalg = true;
              DataInputStream dis = new DataInputStream(s.getInputStream());
              while(bfalg){
              String str = dis.readUTF();
              System.out.println(str);
              }
              dis.close();
              s.close();
      
       }catch (IOException e) {
       e.printStackTrace();
       }
      }
    }
    }
      

  3.   

    第二个try catch位置有问题