Original Post
Hello,
ive been trying to create a server and client that can communicate by sending objects.
I started by sending a predefined Date object and that works:
Server:
Client:
The problem is that i can't get it to work proparly with my objects.
Example class:
Server:
Client:
When i run the programs the client should print the hp value of the object but it gives the following exception : server.Player
Thx for any help
ive been trying to create a server and client that can communicate by sending objects.
I started by sending a predefined Date object and that works:
Server:
public void run() {
try{
oos.writeObject(new Date());
oos.flush();
oos.close();
client.close();
}catch(Exception e) {}
}
Client:
date = (Date) ois.readObject();
System.out.print("The date is: " + date);
The problem is that i can't get it to work proparly with my objects.
Example class:
public class Player implements Serializable {
private int hp;
public Player(){
hp=0;
}
public void sethp(int hp){
this.hp=hp;
}
public int gethp(){
return hp;
}
}
Server:
Player p = new Player();
p.sethp(15);
oos.writeObject(p);
oos.flush();
Client:
Player p = new Player();
p = (Player) ois.readObject();
hp = p.gethp();
System.out.println("player hp: " + hp );
When i run the programs the client should print the hp value of the object but it gives the following exception : server.Player
Thx for any help