高手在吗?求助下这个非常简单的程序
import java.io.*;
import java.net.*;
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Sim{
JTextArea incoming;
JTextField outgoing;
BufferedReader reader;
PrintWriter writer;
Socket sock;
public static void main(String[] args){
new Sim().go();
}
public void go(){
JFrame frame = new JFrame("Simple Chat Client");
JPanel panel = new JPanel();
incoming = new JTextArea(15,50);
incoming.setLineWrap(true);
incoming.setWrapStyleWord(true);
incoming.setEditable(false);
JScrollPane qScroller = new JScrollPane(incoming);
qScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
qScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
outgoing = new JTextField(20);
JButton sendButton = new JButton("send");
sendButton.addActionListener(new sendButtonListener());
panel.add(qScroller);
panel.add(outgoing);
panel.add(sendButton);
setUpNetworking();
Thread readerThread = new Thread(new IncomingReader());
readerThread.start();
frame.getContentPane().add(BorderLayout.CENTER,panel);
frame.setSize(400,500);
frame.setVisible(true);
}
private void setUpNetworking(){
try{
sock = new Socket("127.0.0.1",5000);
InputStreamReader streamReader = new InputStreamReader(sock.getInputStream());
reader = new BufferedReader(streamReader);
writer = new PrintWriter("networking established");
}catch(
IOException ex){
ex.printStackTrace();
}
}
public class sendButtonListener implements ActionListener{
public void actionPerformed (ActionEvent ev){
try{
writer.println(outgoing.getText());
writer.flush();
}catch(Exception ex){
ex.printStackTrace();
}
outgoing.setText("");
outgoing.requestFocus();
}
}
public class IncomingReader implements Runnable{
public void run(){
String message;
try{
while((message = reader.readLine())!= null){
System.out.println("read"+message);
incoming.append(message+"\n");
}
}catch(Exception ex){ex.printStackTrace();}
}
}
}
这个是客户端程序
import java.io.*;
import java.net.*;
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class SimSever{
//ArrayList<Object>clientOutputStreams = new ArrayList<Object>();
ArrayList clientOutputStreams;
public class ClientHandler implements Runnable{
BufferedReader reader;
Socket sock;
public ClientHandler(Socket clientSocket){
try{
sock = clientSocket;
InputStreamReader isReader = new InputStreamReader(sock.getInputStream());
reader = new BufferedReader(isReader);
}catch(Exception ex){ex.printStackTrace();}
}
public void run(){
String message;
try{
while ((message = reader.readLine())!= null){
System.out.println("read"+message);