服务器端报错:java.net.SocketException: Connection reset
package com.imooc.thread; import java.io.IOException; import java.io.InputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.net.Socket; import com.jinxin.entity.File; import com.jinxin.entity.User; import com.jinxin.service.FileService; import com.jinxin.service.UserService; import com.jinxin.util.CommandTransfer; public class ServerThread extends Thread { //和本线程相关的socket Socket socket; public ServerThread (Socket socket){ this.socket =socket; } public void run(){ //3.创建输入流,并读取客户端信息 try { InputStream is = socket.getInputStream(); ObjectInputStream ois = new ObjectInputStream(is);//这是28行 CommandTransfer com=null; try { com = (CommandTransfer)ois.readObject(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } operate(socket,com); socket.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public void operate(Socket socket ,CommandTransfer com) throws IOException{ if(com.getCmd().equals("select")){ UserService userService = new UserService(); if(userService.ckeckout((User)com.getData())){ socket.shutdownInput(); OutputStream os = socket.getOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(os); com.setFlag(true); oos.writeObject(com); oos.flush(); socket.shutdownOutput(); }else{ socket.shutdownInput(); OutputStream os = socket.getOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(os); com.setFlag(false); oos.writeObject(com); oos.flush(); socket.shutdownOutput(); } } if(com.getCmd().equals("register")){ UserService userService = new UserService(); if(userService.ckeckout((User)com.getData())){ socket.shutdownInput(); OutputStream os = socket.getOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(os); com.setFlag(false); oos.writeObject(com); oos.flush(); socket.shutdownOutput(); }else{ userService.register((User)com.getData()); socket.shutdownInput(); OutputStream os = socket.getOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(os); com.setFlag(true); oos.writeObject(com); oos.flush(); socket.shutdownOutput(); } } if(com.getCmd().equals("upload")){ FileService fileService = new FileService(); fileService.upload((File)com.getData()); socket.shutdownInput(); } } }
这是项目地址:http://www.imooc.com/opus/resource?opus_id=3426