新手起步求大神解释聊天项目:chat客户端,server 服务端
程序目的:把客户端发送的消息传到服务器端
现在出现的问题是在server中出现java.net.SocketException: Connection reset 这个问题出现问题处有标记当我把异常处理结果(打印异常) 注(//)掉就会编译正常,不注(//)时就会出现异常为什么会出现这个问题import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;public class chat extends Frame{

DataOutputStream dos = null;
Socket s ;
TextField tfText = new TextField();
TextArea taText = new TextArea();

public static void main (String [] args){

new chat().launchFrame();
}

public void launchFrame(){
setBounds(400,150,500,450);
add(tfText,BorderLayout.SOUTH);
add(taText,BorderLayout.CENTER);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
try{
s.close();
}catch (IOException e1){
e1.printStackTrace();
}
}
});
tfText.addActionListener(new TFListener());
setVisible(true);
connect();
}

public void connect(){
try{
s = new Socket("127.0.0.1",8888);
dos = new DataOutputStream(s.getOutputStream());
}catch (UnknownHostException e){
e.printStackTrace();
}
catch (IOException e){
e.printStackTrace();   //注掉这句就会编译正常 
}
}

class TFListener implements ActionListener{
public void actionPerformed(ActionEvent e){
String str = tfText.getText();
taText.setText(str);
tfText.setText("");
try{
dos.writeUTF(str);
dos.flush();
//dos.close();
}catch (IOException e1){
e1.printStackTrace();
}


}
}
}
服务器端:
import java.io.*;
import java.net.*;public class server{ Socket s =null;
ServerSocket ss = null;
boolean start = false;
DataInputStream dis = null;

public static void main(String [] args){
new server().start();
}

public void start(){
try{
ss = new ServerSocket(8888);
}catch(BindException e){
System.out.println("端口已被使用");
System.out.println("请关闭后。重新运行");
System.exit(0);
}catch(IOException e){
e.printStackTrace();
}
try{
start = true;
while(start){
boolean bConnect = false;
s = ss.accept();
bConnect = true;
//System.out.println("s connected ");
dis = new DataInputStream(s.getInputStream());
while(bConnect){
String str = dis.readUTF();
System.out.println(str);
}
//dis.close();
}
}catch(EOFException e){
System.out.println("chat close");
}catch(IOException e){
//e.printStackTrace();  //出现异常的地方 把这句注 掉就会编译正常
}finally{
try{
if(dis!=null)dis.close();
if(s!=null)s.close();
}catch (IOException e){
e.printStackTrace();
}

}
}
}
聊天小项目中出现的问题   求解决大神