//客户端
public boolean sendLoginInfoToServer(Object o){
boolean b=false;
try{
Socket s=new Socket("127.0.0.1",46544);
ObjectOutputStream oos=new ObjectOutputStream(s.getOutputStream());
oos.writeObject(o);
System.out.println(o.toString());//这里可以执行
ObjectInputStream ois=new ObjectInputStream(s.getInputStream());//这里怎么抛出 SocketException异常啊
System.out.println("333333333");
ManagQQFiredList mfl=(ManagQQFiredList)ois.readObject();
if("1".equals(mfl.getManagType())){
b= true;
}else{
b= false;
}
}catch(IOException e){
e.printStackTrace();
}
catch(Exception e){
e.printStackTrace();
}finally{
}
return b;
}
//服务器端
public MyQQServer(){
try{
System.out.println("我是服务器");
//在9999监听
ServerSocket ss=new ServerSocket(46544);
//阻塞 等待连接
while(true){
Socket s=ss.accept();
//接受客户端发来的信息
ObjectInputStream ois=new ObjectInputStream(s.getInputStream());
Object oo=ois.readObject();
User u=(User)oo;//java.lang.ClassNotFoundException
System.out.println(u.getUserId()+" "+u.getPassword());
ManagQQFiredList m=new ManagQQFiredList();
if("123456".equals(u.getPassword())){
//返回一个成功登录信息包
m.setManagType("1");
}else{
m.setManagType("2");
}
ObjectOutputStream oos=new ObjectOutputStream(s.getOutputStream());
oos.writeObject(m);
}
}catch(Exception e){
e.printStackTrace();
}finally{
}
}求大神指点下 为什么读不到对象啊socket
public boolean sendLoginInfoToServer(Object o){
boolean b=false;
try{
Socket s=new Socket("127.0.0.1",46544);
ObjectOutputStream oos=new ObjectOutputStream(s.getOutputStream());
oos.writeObject(o);
System.out.println(o.toString());//这里可以执行
ObjectInputStream ois=new ObjectInputStream(s.getInputStream());//这里怎么抛出 SocketException异常啊
System.out.println("333333333");
ManagQQFiredList mfl=(ManagQQFiredList)ois.readObject();
if("1".equals(mfl.getManagType())){
b= true;
}else{
b= false;
}
}catch(IOException e){
e.printStackTrace();
}
catch(Exception e){
e.printStackTrace();
}finally{
}
return b;
}
//服务器端
public MyQQServer(){
try{
System.out.println("我是服务器");
//在9999监听
ServerSocket ss=new ServerSocket(46544);
//阻塞 等待连接
while(true){
Socket s=ss.accept();
//接受客户端发来的信息
ObjectInputStream ois=new ObjectInputStream(s.getInputStream());
Object oo=ois.readObject();
User u=(User)oo;//java.lang.ClassNotFoundException
System.out.println(u.getUserId()+" "+u.getPassword());
ManagQQFiredList m=new ManagQQFiredList();
if("123456".equals(u.getPassword())){
//返回一个成功登录信息包
m.setManagType("1");
}else{
m.setManagType("2");
}
ObjectOutputStream oos=new ObjectOutputStream(s.getOutputStream());
oos.writeObject(m);
}
}catch(Exception e){
e.printStackTrace();
}finally{
}
}求大神指点下 为什么读不到对象啊socket
解决方案 »
- 作业的一道加分题求帮助。
- web人员开始学习wap开发,大家有什么好的建议么?
- jvm的垃圾回收机制用的是什么算法
- 帮忙解决一个问题
- 求助!关于java 多态和重写的一个问题
- 还是不能实现的问题!各位帮一下!
- 为什么打印不出"\b"啊
- Type mismatch: cannot convert from Object to Object[] ,求助
- AWT事件(MouseAdaptor)
- 绝对初级:exeption in thread "main" java.lang.noclassdeffounderror:myfirst
- 关于sqlserver数据库连接的小问题
- 验证邮箱的正则表达式,有个问题好像,求解
这句话你想实现什么功能呢?
我看你的服务器端只有接受,没有发送,可是你客户端为什么要接受呢?
另外你把对象写入了输出流中,那么你是不是应该flush刷新一下让其发送呢?
flush()也报错
应为客户端那边要用
代码是跟真韩顺平老师的山寨qq敲的