import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;
public class ServerBiz extends Thread{
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new ServerBiz().start();
}
public void run()
{
ServerSocket serverSocket=null;
Socket socket=null;
ObjectInputStream ois=null;
ObjectOutputStream oos=null;
try {
serverSocket=new ServerSocket(Integer.parseInt(Tools.getValue(Sysconstants.SYS_LISTENERPORT)));
while(true)
{ ServerService serverService=new ServerService();
socket=serverSocket.accept();
ois=new ObjectInputStream(socket.getInputStream());//运行客户端无法得到结果,停止后显示这里出问题
oos=new ObjectOutputStream(socket.getOutputStream());
Datas datas=(Datas) ois.readObject();
if(datas.getflag().equals(Sysconstants.SYS_LOGIN));
{
String username=datas.getUser().getUsername();
String password=datas.getUser().getPassword();
User user=serverService.doLogin(username, password);
if(user==null)
{
datas.setFlag(Sysconstants.SYS_ERROR);
}
else
{
datas.setFlag(Sysconstants.SYS_SUCCESS);
datas.setUser(user);
}
}
if(datas.getflag().equals(Sysconstants.SYS_CREATE))
{
String username=datas.getUser().getUsername();
String password=datas.getUser().getPassword();
User user=serverService.createNewAccount(username, password);
if(user==null)
{
datas.setFlag(Sysconstants.SYS_ERROR);
}
else
{
datas.setFlag(Sysconstants.SYS_SUCCESS);
datas.setUser(user);
}
}
oos.writeObject(datas);
oos.close();
ois.close();
socket.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
这个是问题显示
java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at java.io.ObjectInputStream$PeekInputStream.read(Unknown Source)
at java.io.ObjectInputStream$PeekInputStream.readFully(Unknown Source)
at java.io.ObjectInputStream$BlockDataInputStream.readShort(Unknown Source)
at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
at java.io.ObjectInputStream.<init>(Unknown Source)
at com.luna.server.ServerBiz.run(ServerBiz.java:43)
我完全不知道怎么回事,应该没有错啊 |