我必須從客戶端向服務器端發送一個Person類的對象,但是在服務器中沒有類Person,怎麼辦? Person的屬性是nome和cognome。如何從客戶端向服務器發送對象?
// CLIENT
Socket sock = new Socket("localhost",10000);
ObjectOutputStream outToClient = new ObjectOutputStream(sock.getOutputStream());
String nome = "Mario";
String cognome = "Rossi";
Giocatore giocatore = new Giocatore(nome,cognome);
outToClient.writeObject(giocatore);
// SERVER
ServerSocket ser = new ServerSocket(10000);
Socket sock = ser.accept();
ObjectInputStream inFromClient = new ObjectInputStream(sock.getInputStream());
?????
可能重複的[在java中通過套接字發送對象](http://stackoverflow.com/questions/19217420/sending-an-object-through-a-socket-in-java) – plalx
你不能沒有車就開車。沒有飛機,你不能坐飛機。如果沒有Person類,則無法讀取Person類的對象。 –