我正在尝试通过套接字发送一个对象。
其对象网
public class Net {
public List<NetObject> objects; //= new ArrayList<NetObject>(); // place + transition
public List<ArcObject> arcs; // = new ArrayList<ArcObject>(); // arcs - objects
}
这是 ArcObject 类
public class ArcObject implements Observer {
public NetObject o1;
public NetObject o2;
public String parameter;
}
这是 NetObject 类
public class NetObject implements Observer{
public int index; // index of object
public int type; // type - place=1, transition=2 ...
public int x; // position
public int y;
public List<Integer> tokens ; //list of tokens
//public List<ArcObject> arcs = new ArrayList<ArcObject>();
public String guard;
// etc...
}
然后我连接到服务器
String computername=InetAddress.getLocalHost().getHostName();
kkSocket = new Socket(computername, 4444);
OutputStream outputStream = null ;
ObjectOutputStream out = null ;
outputStream = kkSocket.getOutputStream();
out = new ObjectOutputStream(outputStream);
然后我尝试通过套接字发送对象
out.writeObject(petriNet); //petriNet object is from class Net
但客户给了我一个例外
java.io.NotSerializableException: petri.ArcObject
但是 ArcObject 类不能实现 Serializable,因为它已经实现了 Observer,所以我应该如何通过包含两个列表的套接字发送对象。有任何想法吗 ?