ObjectOutputStream を介して自作のオブジェクトを送信する場合、そのオブジェクトのサーバー クラスとクライアント クラスは同じである必要がありますか?
たとえば、サーバーでのみ使用可能な他のいくつかのクラスが必要なため、一部のアクションをサーバーでのみ実行できる場合、クライアント上のクラスはサーバー上のクラスと異なる可能性がありますか?
サーバークラス:
public class SomeAction implements Action, Serializable {
private static final long serialVersionUID = 1L; //Just some serialVersionUID
private String name;
public SomeAction(String name) {
//This property must be sent to the server
this.name = name;
}
@Override
public void performAction() {
System.out.println("New client connected");
Server.getConnections().add(1); //Increases the number of connections on the server. Of course, this is only available on the server.
//Do something with the client
. . .
}
}
クライアントクラス:
public class SomeAction implements Action, Serializable {
private static final long serialVersionUID = 1L; //Just some serialVersionUID
private String name;
public SomeAction(String name) {
//This property must be sent to the server
this.name = name;
}
@Override
public void performAction() {
System.out.println("New client connected");
//The getConnections().add(1) wont work on the client.
//Do something with the client
. . .
}
}
これで、クライアントはそのクラスをサーバーに送信できます。サーバーはperformAction()
独自のクラスからメソッドを呼び出しますか?