problem with serialization
Hi
I Am trying to write simple Server ?client application in netbeans. I have written two projects one for server one for client. Client program sends an object to server which is trying to receive this object. After sending simple object I get
java.lang.ClassNotFoundException: client.Factory
on server. Client and server projects both contain declarations of class Factory which I am trying to send. What am I doing wrong?
Below is code for projects:
//*******Class Factory the same for server and client***********
import java.io.*;
import java.util.*;
public class Factory implements Serializable{
int i;
public Factory() {
this.i=666;
}
}
//************client*************************
package client;
import java.io.*;
import java.net.*;
import java.util.*;
public class Main {
public Main() {
}
public static void main(String[] args) {
try
{ObjectOutputStream os;
Socket sock = new Socket("192.168.0.14", 8189);
String a = new String("test");
Factory fa = new Factory();
os = new ObjectOutputStream((sock.getOutputStream()));
os.writeObject(fa);
}
catch (Exception ex)
{}
}
}
//**********server******************
package objectserver;
import java.io.*;
import java.net.*;
import java.util.*;
public class Main {
public Main() {
}
public static void main(String[] args) {
try{
ObjectInputStream is;
ServerSocket servSock = new ServerSocket(8189);
Socket sock;
Factory o = new Factory();
sock = servSock.accept();
is = new ObjectInputStream(sock.getInputStream());
o = (Factory)is.readObject();
}
catch (Exception ex){
System.out.println(ex);
}
}
}
Message was edited by:
spock_michal

