对象流问题
public class MyChatServer {
public MyChatServer (){
try{
//在6789监听
ServerSocket ss=new ServerSocket(12345);
//等待链接
System.out.print("okoko");
Socket s=ss.accept();
//未成功
ObjectInputStream ois=new ObjectInputStream(s.getInputStream());
User u=(User)ois.readObject();
Message ms = new Message();
if(u.getUserPwd().equals("123456")){
//返回登入成功
ms.setMesType("1");
}
else ms.setMesType("2");
ObjectOutputStream oos=new ObjectOutputStream(s.getOutputStream());
// oos.writeObject(ms);
oos.writeUnshared(ms);oos.flush();
}catch(Exception e){
e.printStackTrace();
}
}
}
public class ChatClientConServer {
//第一次链接
boolean b=false;
public boolean SendLoginMegToServer(User u){
try {
Socket s=new Socket("127.0.0.1",12345);
System.out.print("cli");
ObjectOutputStream oos=new ObjectOutputStream(s.getOutputStream());
// oos.writeObject(u);
oos.writeUnshared(u);
System.out.print(u.getUserId()+"\n"+u.getUserPwd());
ObjectInputStream ois=new ObjectInputStream(s.getInputStream());
Message ms=(Message)ois.readObject();System.out.print("client");
// Message ms=new Message();ms.setMesType("1");
if(ms.getMesType().equals("1")){
b=true;
}
} catch (Exception e) {
e.printStackTrace();
}
//finally{}
return b;
}
}
客户端发了一个对象后,服务器读取不到
------解决方案--------------------//在6789监听
ServerSocket ss=new ServerSocket(12345);
到底在哪个端口????