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

[1954 byte] By [spock_michala] at [2007-10-2 18:57:14]
# 1
The code you have posted is not the same as the code you are executing. The server is looking for a class named Factory in the package client. That class is probably not available on the server.Kaj
kajbja at 2007-7-13 20:35:32 > top of Java-index,Core,Core APIs...
# 2
A have deleted package declarations and it seams to work. Where should I place class Factory declaration one server and client side if server and client are in deferent packages?
spock_michala at 2007-7-13 20:35:32 > top of Java-index,Core,Core APIs...
# 3
It doesn't matter in what package you place the Factory class as long as both sides have that class on the classpath. Classes can also be loaded dynamically but that's a bit trickier.Kaj
kajbja at 2007-7-13 20:35:32 > top of Java-index,Core,Core APIs...
# 4
I guess you named the Factory class in client project in package client and in server project in package server.Write the class at only one place and say server and define classpath for client in which the server files will be available.
bbhangalea at 2007-7-13 20:35:32 > top of Java-index,Core,Core APIs...