我想通过套接字发送一个对象。如何通过套接字发送列表java
它的对象网
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,因为它已经实现了观测,所以我怎么应该通过包含两个列表的套接字发送对象。 有什么想法?