Socket Client1=null; int i = 0; TextArea in; int port,k=0,l=0;
PrintStream theOutputStream; Face chat;
public Server(int port, Face chat) { try {
this.port = port;
skt = new ServerSocket(port); this.chat = chat;
} catch (IOException e) {
chat.ta.append(e.toString()); } }
public void run() {
chat.ta.append("等待连线......"); while (true) { try {
Client[k] = skt.accept();
//当有客户端连接时就新建一个子线程 if (i < 2) {
ServerThread server[] = new ServerThread[10]; server[k]= new ServerThread(Client[k], this.chat, i); l=server.length; server[k].start();
chat.ta.append(“客户端“+ Client*k+.getInetAddress() + "已连线\n");
//for(int j=0;j<server.length;j++)
theOutputStream = new PrintStream(server[k].getClient().getOutputStream()); i = server[k].getI(); k++; } else {
//theOutputStream = new PrintStream(null); }
} catch (SocketException e) { } catch (IOException e) {
chat.ta.append(e.toString()); } } }
public void dataout(String data) { //for(int j=0;j<l;j++)
theOutputStream.println(data);