当前位置:首页
开发技术指南» 文章正文
    引言:

 ·怎么在classview里少了一些类呀    »显示摘要«
    摘要: 我用vc建了个基本对话框的工程,打开时,在classview中看不到对话框的类,只是 看到应用程序类(app),编译是任何问题的,编译出来的 exe也运行正常,这是怎么会事? 多谢指教! ......
 ·求教    »显示摘要«
    摘要: 在sql server中,怎么样操作将一次的查询结果保存在一个新表中,此查询每天都要做,而且把每天的记过都是追加的方式放在同一个表中呢? 是否需要用"视图" ......


Java中使用ObjectInputStream,ObjectOutputStream转递对象的问题

在学习使用JAVA做网络时需要用ObjectInputStream和ObjectOutputStream从客户端转递一个对象到服务器,却遇到一个奇怪的问题。源码如下:  
  服务器端:  
  public   class   Server  
  {  
      class   Msg   implements   Serializable  
      {  
  String   s1;  
  String   s2;  
      }  
   
      Server()  
      {  
  try  
  {  
  ServerSocket   server=new   ServerSocket(6666);  
  Socket   s=server.accept();  
  ObjectInputStream   ois=new   ObjectInputStreams.getInputStream());  
  Msg   temp=new   Msg();  
  temp=(Msg)ois.readObject();  
  System.out.println(temp.s1);  
  System.out.println(temp.s2);  
  }  
  catch(Exception   e)  
  {  
  System.out.println(e);  
  }  
      }  
      public   static   void   main(String   s[])  
      {  
  new   Server();  
      }  
  }  
  客户端:  
  public   class   Client  
  {  
      class   Msg   implements   Serializable  
      {  
  String   s1;  
  String   s2;  
      }  
   
      Client()  
      {  
  try  
  {  
  Socket   s=new   Socket("127.0.0.1",6666);  
  ObjectOutputStream   oos=new   ObjectOutputStream(s.getOutputStream());  
  Msg   temp=new   Msg();  
  temp.s2="1";  
  temp.s2="2";  
  oos.writeObject(temp);  
  }  
  catch(Exception   e)  
  {  
  System.out.println(e);  
  }  
      }  
      public   static   void   main(String   s[])  
      {  
  new   Client();  
      }  
  }  
  运行后在客户端显示一个"java.io.NotSerializableException:   Client"异常,在服务器端显示一个“java.net.SocketException:   Connection   reset”异常。  
  请问各位高手这个问题应该怎么解决。

NO.1   作者: Yoinn

你传送的对象必须Serializable

NO.2   作者: tiger_wkh52741

public   class   Server     implements   Serializable  
  {  
      class   Msg   {  
      //..........  
      }  
  }  
  //....

NO.3   作者: jokerjava

搂主的程序有一个问题  
  两个类中Msg类     并不是一个类     反序列化的时候会抛错的  
  其他的地方没有问题      
   
  把Msg类改成public类     就没问题了  
   
   
 

NO.4   作者: llpei

我的一点建议  
  将公用的message提出来,不要用内部类,应为那时两个不同的对象  
  Message:  
  public   class   Msg   implements   java.io.Serializable{  
            String   s1;  
            String   s2;  
  }  
   
  Server:  
  public   class   Server  
  {  
        Server()  
      {  
          try  
          {  
                  ServerSocket   server=new   ServerSocket(6666);  
                  Socket   s=server.accept();  
                  ObjectInputStream   ois=new   ObjectInputStream(s.getInputStream());  
                  Msg   temp=new   Msg();  
                  temp=(Msg)ois.readObject();  
                  System.out.println(temp.s1);  
                  System.out.println(temp.s2);  
          }  
          catch(Exception   e)  
          {  
                  System.out.println(e);  
          }  
      }  
      public   static   void   main(String   s[])  
      {  
          new   Server();  
      }  
  }  
  Client:  
  public   class   Client   {  
   
   
        Client()  
        {  
            try  
            {  
                    Socket   s=new   Socket("127.0.0.1",6666);  
                    ObjectOutputStream   oos=new   ObjectOutputStream(s.getOutputStream());  
                    Msg   temp=new   Msg();  
                    temp.s2="1";  
                    temp.s2="2";  
                    oos.writeObject(temp);  
            }  
            catch(Exception   e)  
            {  
                    System.out.println(e);  
            }  
        }  
        public   static   void   main(String   s[])  
        {  
            new   Client();  
        }  
  }

NO.5   作者: rongrongGsr

client类也要implements   Serializable


 ·dx们一问题    »显示摘要«
    摘要: 有以下脚本在zt.sql文件里面 我如何把它读入,然后创建到已有的数据库sw里面 如何处理go呢?好象用adoquery遇到go就出错 create table [dbo].[j_goods] ( [spbh] [varchar] (20) collate chinese_prc_ci_as not null , [txm] [varchar] (20) collate chinese......
» 本期热门文章:

©2000-2007 All Rights Reserved. 最佳浏览:1024X768 MSIE