CLSendStruct 是否实现串型化接口:java.io.Serializable
还有你的输入,输出流是怎么重定向的?

解决方案 »

  1.   

    我的输入流为一个结构体,如何将CLSendStruct 实现串型化接口
      

  2.   

    只需要
     public class CLSendStruct implements java.io.Serializable
     {
       //你原有的定义
     }
      

  3.   

    对没错,我就是如此的,有类没发现错误
    java.lang.ClassNotFoundException: airtserver.CLSendStruct
      

  4.   

    receiveSTRK 为CLSendStruct的对象
    receiveSTRK = (CLSendStruct)clientReceive.readObject()
    这一个有错误
      

  5.   

    public class AirTest{
      public static void  main(String[] args)throws IOException{
        CLSendStruct sendSTRK = new CLSendStruct();    Socket airSocket;
        //BufferedReader socketInput;
        //DataOutputStream socketOutput;
        ObjectInputStream InputStream = null;
        ObjectOutputStream OutputStream = null;
        ObjectOutputStream OOS = null;// = new ObjectOutputStream(;
        //sendSTRK.setCommand(args[0].getBytes());
        try{
          System.out.println("Connect...");
          airSocket = new Socket("127.0.0.1",1024);
          OutputStream = new ObjectOutputStream(airSocket.getOutputStream ());
          InputStream  = new ObjectInputStream(airSocket.getInputStream ());      //DisplayReply(ObjectInputStream);      System.out.println("Command + TEST");
          sendSTRK.setCommand("TEST".toCharArray());
          sendSTRK.setResult("qqqqqqqqqq".toCharArray());
          sendSTRK.equals(OOS);      //OutputStream.write(sendSTRK.getPool().toString().getBytes());
          OutputStream.writeObject(sendSTRK);
          OutputStream.flush ();
          DisplayReply(InputStream);
    /*
          System.out.println("Command1 + QUIT");
          sendSTRK.setCommand("QUIT".toCharArray());
          sendSTRK.setResult("PPPPPPPPPPP".toCharArray());
          sendSTRK.equals(OOS);      OutputStream.writeObject (sendSTRK);
          OutputStream.flush ();
          DisplayReply(InputStream);      //this.m_msg  = (Message) p_ObjectInputStream.readObject();*/      OutputStream.close();
          InputStream.close();
          airSocket.close();
        }catch(Exception e){
          System.out.println("exception: "+e);
        }
        System.exit(0);
      }  private static void DisplayReply(ObjectInputStream inputStream) throws IOException,Exception{
        ObjectInputStream OIS = null;
        String s = new String();
        CLSendStruct receiveSTRK = new CLSendStruct();
        try{
          //inputStream.equals(receiveSTRK);
          System.out.println("qq  "+receiveSTRK.toString());
          //receiveSTRK.equals(inputStream);
          receiveSTRK= (CLSendStruct)inputStream.readObject();
          System.out.println("qq  "+receiveSTRK.toString());
          s = receiveSTRK.getSuccID().toString();
          if (s == "1"){
            s = receiveSTRK.getResult().toString();
            System.out.println("SUCCESS  "+receiveSTRK.getGWTime().toString());
            System.out.println(s);
          }else
            System.out.println("NO SUCCESS  "+receiveSTRK.getGWTime().toString());
        }catch(Exception e){
          System.out.println("111111  "+e);
        }
      }
    }
    public class CLSendStruct  implements Serializable{  private char[] Command = new char[100];  //发送查询命令
      private char[] Result = new char[4000];
      public CLSendStruct(){
      }
      下面为getXX(),setxx()
    }
    服务器 public AirHandler(Socket newSocket){    mySocket = newSocket;
      }  public void run(){
        //java.sql.Connection con;
        //java.sql.Statement stmt = null;
        String nextLine;
        StringTokenizer tokens;
        String command;
        stockInfoTime = new Date();
        try{
          clientReceive   = new ObjectInputStream(mySocket.getInputStream ());
          clientSend  = new ObjectOutputStream(mySocket.getOutputStream ());
        /*  sendSTRK.setSuccID("1".toCharArray());
          sendSTRK.setResult("HELLO WORLD !!!".toCharArray());
          sendSTRK.equals(OOS);
          clientSend.writeObject(OOS);*/
          try{
              //clientReceive.readObject().equals(receiveSTRK);
              System.out.println("command: 1");
              while((receiveSTRK = (CLSendStruct)clientReceive.readObject())!= null){
              //break the line into tokens
                //tokens = new StringTokenizer(nextLine);
                System.out.println("command: 2");
                try{
                  command = receiveSTRK.getCommand().toString();
                  System.out.println("command: "+command);
                  //quit command
                  if(command.equalsIgnoreCase("QUIT")){ 
                     sendSTRK.setxx();
                     clientSend.writeObject(sendSTRK);;
                   }
                  //stock command
               }catch(NoSuchElementException excpt){
                  sendSTRK.setSuccID("0".toCharArray());
                  sendSTRK.setResul("NoSuchElementException".toCharArray());
                  sendSTRK.equals(OOS);
                  clientSend.writeObject(sendSTRK);
                }
            }
    谢谢帮忙
      

  6.   

    receiveSTRK = (CLSendStruct)clientReceive.readObject()
    这一句
      

  7.   

    上为服务器,下为客户端
    receiveSTRK= (CLSendStruct)inputStream.readObject();
      

  8.   

    OutputStream.writeObject (sendSTRK);
    这是写的
      

  9.   

    你读写一个简单的数据可以吗?
    OutputStream.writeInt(100); //ClientinputStream.readInt() ; //Server你试试可以读到这个100吗?
      

  10.   

    sendSTRK.setCommand("QUIT".toCharArray());你为什么这么用:"QUIT".toCharArray();
    你定义的结构里面有字符数组?
    如果有数组,你的数组是否实现序列化接口呢?
      

  11.   

    public class CLSendStruct  implements Serializable{  private char[] Command = new char[100];  //发送查询命令
      private char[] Result = new char[4000];
      public CLSendStruct(){
      }
      下面为getXX(),setxx()
    }难道这样序列化不行吗?
    如何对字符数组进行序列化