How to send an OBJECT over TCP in java?

前端 未结 3 1741
耶瑟儿~
耶瑟儿~ 2020-12-12 03:45

I\'m writing a program to send an object from one class to another class. Here is a short sample example of my program to represent the problem. As you can

3条回答
  •  Happy的楠姐
    2020-12-12 04:15

    You cannot ever deserialize a stream representing an instance of class X into an instance of class Y.

    To solve your problem, you need to move the code for the Student class to another file, say Student.java, and use that single class on your client code and on your server code.

    Note that if you modify your class, in most cases you will need to redeploy the server (otherwise the client would send the server an stream representing an instance of class that is known only to the client).

提交回复
热议问题