0 LIKES LikeUnLike
I'm using object input and output streams to send and receive objects through sockets. The client receives the first object, but when I send another objects it crashes (StreamCorruptedException). Does anyone know how to fix this?I used global variables for the object input and output streams and the socket. The methods are pretty much the same on both sides of the socket(One sends MAC objects and receives MAS objects and the other sends MAS and receives MAC):To initialize the streams:private void getStreams() throws IOException{out=new ObjectOutputStream(newBufferedOutputStream(socket.getOutputStream()));out.flush();in=new ObjectInputStream(newBufferedInputStream(socket.getInputStream()));}To send an object:public void send(Object obj){try {MAS m = new MAS(obj);//MAS implements serializableout.writeObject(m);out.flush();out.reset();}catch ( IOException e) {}}To receive an object:private void receive() throws IOException{MAC m;//MAC implements Serializabledo {try {m=(MAC)in.readObject();m.setP(this);m.chooseAction();}catch ( ClassNotFoundException e) {}} while (true);}
Tags:
Report (0) (0) | earlier
Latest activity: earlier. This question has 1 answers.