クライアントとサーバーの間でオブジェクトをバウンスできません。
オブジェクトを作成します。一部のフィールドを更新します。サーバーに送信します。(この部分は機能します)
SomeObject thisObject = new SomeObject();
thisObject.setSomeValue(13); // update object to be sent
PrintStream toServer = new PrintStream(sock.getOutputStream());
ObjectOutputStream oos = new ObjectOutputStream(toServer);
oos.writeObject(thisObject);
oos.close();
toServer.println(oos); // send object to server
toServer.flush();
この直後、サーバーはさらにいくつかの値を更新し、1919 に設定します。
ObjectInputStream objFromClient = new ObjectInputStream(new BufferedInputStream(
sock.getInputStream()));
Served thisObject = (Served) objFromClient.readObject();
thisObject.setSomeValue(1919);
次に、サーバーはオブジェクトをクライアントに送り返します
toClient = new PrintStream(sock.getOutputStream());
ObjectOutputStream oos = new ObjectOutputStream(toClient);
oos.writeObject(thisObject);
oos.close();
objFromClient.close();
sock.close();
しかし、クライアント側でオブジェクトを取得するときが来ると..プログラムはSocket Closed例外で失敗します
ObjectInputStream objFromServer = new ObjectInputStream(
new BufferedInputStream(sock.getInputStream())); //java.net.SocketException: Socket is closed
thisObject = (Served) objFromServer.readObject();
....
問題を理解するのを手伝ってください