Hello!
I have met problem that i cant climb over even if i've tried many different ways and asked for help. But i've never managed to make it work, its about object streams that corrupts / "invalid type code: AC". This is the way how i want it to work:

Client connects to the server, server makes new thread for client and listens to it and whenever the client writes object on stream that server listens for the server sends the object to every connected client.

Whenever i connect to the client i am able to send a object to it and receive it back but when i do that again i got error! "java.io.StreamCorruptedException: invalid type code: AC" How can i avoid this and what causes this? I've heared its about the headers of streams. I got no idea whats wrong. I know google is nice friend but this time it doesnt just help me! :eek:

Heres my code.

This is the server:

Java Code:
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;


public class server {
	ServerSocket ss;
	List<Socket> users = new ArrayList<Socket>();
	public static void main(String args[]){
		new server();
	}
	
	server(){
		try {
			ss = new ServerSocket(1234);
		} catch (IOException e) {
			e.printStackTrace();
		}
		while(true){
			Socket s = null;
			try {
				s = ss.accept();
			} catch (IOException e) {
				e.printStackTrace();
			}
			users.add(s);
			new handler(s).start();
		}
	}
	
	class handler extends Thread{
		Socket s;
		Object o;
		ObjectInputStream ois;
		
		handler(Socket s){
			this.s = s;
		}
		
		public void run(){
			try {
				ois = new ObjectInputStream(s.getInputStream());
			} catch (IOException e) {
				e.printStackTrace();
			}
			while(s.isConnected()){
				try {
					o = ois.readObject();
					sendAll(o);
				} catch (IOException e) {
					e.printStackTrace();
					stop();
				} catch (ClassNotFoundException e) {
					e.printStackTrace();
					stop();
				}
			}
		}
	}
	
	void sendAll(Object obj){
		for(int x = 0; x < users.size(); x++){
			try {
				new ObjectOutputStream(users.get(x).getOutputStream()).writeObject(obj);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}
and this is the client that connects to the server:

Java Code:
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;


public class client {
	Socket s;
	ObjectOutputStream oos;
	public static void main(String args[]){
		new client();
	}
	client(){
		try {
			s = new Socket("localhost", 1234);
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		new reader(s).start();
		Scanner in = new Scanner(System.in);
		try {
			oos = new ObjectOutputStream(s.getOutputStream());
		} catch (IOException e) {
			e.printStackTrace();
		}
		while(true){
			try {
				oos.writeObject(new human(in.nextLine()));
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
	class reader extends Thread{
		ObjectInputStream ois;
		Socket s;
		
		reader(Socket s){
			this.s = s;
		}
		public void run(){
			try {
				ois = new ObjectInputStream(s.getInputStream());
			} catch (IOException e1) {
				e1.printStackTrace();
			}
			while(true){
				try {
					human i = (human) ois.readObject();
					System.out.println(i);
				} catch (IOException e) {
					e.printStackTrace();
				} catch (ClassNotFoundException e) {
					e.printStackTrace();
				}
			}
		}
	}
}
and the object i want to send over internet(i know theres no mind! but this is just an example, and i want to understand more about sockets / object streams)

Java Code:
import java.io.Serializable;


public class human implements Serializable {
	String name;
	human(String name){
		this.name = name;
	}
	public String toString(){
		return "Humans name is "+name;
	}
}
Please tell me what is wrong and why?