I have to create two client-server applications to send a person type object from the server to the client. The problem is that reading it in the client gives error because it has not found the class. I put the code, the truth that I do not give with the error. The person class is in the two projects
Person class:
public class Persona implements Serializable {
private String nombre;
private int edad;
public Persona (String nombre, int edad){
super();
this.nombre=nombre;
this.edad=edad;
}
public String getNombre (){
return nombre;
}
public void setNombre(String n){
this.nombre=n;
}
public int getEdad (){
return edad;
}
public void setEdad (int a){
this.edad=a;
}
Server class:
public class Servidor {
static final int Puerto=1500;
public Servidor(){
try {
// Inicio el servidor en el puerto
ServerSocket skServidor = new ServerSocket(Puerto);
System.out.println("Escucho el puerto " + Puerto );
Socket skCliente = skServidor.accept(); // Crea objeto
// Creo el flujo de salida
ObjectOutputStream flujo_salida= new ObjectOutputStream(skCliente.getOutputStream());
// Creo el flujo de entrada
ObjectInputStream flujo_entrada= new ObjectInputStream(skCliente.getInputStream());
System.out.println("Cliente conectado");
Persona persona=new Persona("Pablo",35);
flujo_salida.writeObject(persona);
// Se cierra la conexión
skCliente.close();
flujo_entrada.close();
flujo_salida.close();
System.out.println("Cliente desconectado");
} catch (IOException ex) {
Logger.getLogger(Servidor.class.getName()).log(Level.SEVERE, null, ex);
}
}
Client Class:
public class Cliente {
static final String HOST = "localhost";
static final int Puerto=1500;
public Cliente( ) {
Persona persona=null;
try{
// Me conecto al puerto
Socket skCliente = new Socket( HOST , Puerto );
// Creo el flujo de salida
ObjectOutputStream flujo_salida= new ObjectOutputStream(skCliente.getOutputStream());
// Creo el flujo de entrada
ObjectInputStream flujo_entrada= new ObjectInputStream(skCliente.getInputStream());
System.out.println("Conectado al servidor");
persona=(cliente.Persona) flujo_entrada.readObject();
// Se cierra la conexión
skCliente.close();
flujo_entrada.close();
flujo_salida.close();
System.out.println("Cliente desconectado");
} catch( Exception e ) {
System.err.println( e.getMessage()+" "+e.toString() );
}
}