I create my class in the client and use the server to communicate between the client and server, but I have a problem converting this class. I send an object of my class from the client to the server, but the server notices this object from the same class.
My class implements Serializable, and I use ObjectInputStream and ObjectOutputStream to send and receive this object.
How can I tell the server that this object belongs to the same class as on the client?
//Client site.
toServer = new ObjectOutputStream(myClient.getOutputStream());
fromServer = new ObjectInputStream(myClient.getInputStream());
toServer.writeObject(new MyClass("12345",12345));
//Server site.
fromClient = new ObjectInputStream(connectFromClient.getInputStream());
toClient = new ObjectOutputStream(connectFromClient.getOutputStream());
MyClass message = (MyClass) fromClient.readObject();
source
share