Hallo,
I did multiclient chat, but some is wrong, becouse when i run this program, First client send message and server this message recive to another client it is right but second message is lost. I think problem is somewhere that Input or output block program. But I am beginner and i canīt find this error.
Server code:
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
 
/**
 *
 * @author Lolek
 */
public class Main {
 
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try {
            int port = 5000;
            ServerSocket serverSocket = null;
            Socket socket = null;
 
            serverSocket = new ServerSocket(port);
            while (true) {
                socket = serverSocket.accept();
                ChatHandler handler = new ChatHandler(socket);
                handler.start();
            }
        } catch (IOException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
 
 
 
    }
}
class ChatHandler extends Thread
{
     static Vector handlers = new Vector(10);
     private Socket socket;
     private BufferedReader read;
     private BufferedWriter write;
 
     public ChatHandler(Socket socket)
     {
        try {
            this.socket = socket;
            this.read = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            this.write = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
        } catch (IOException ex) {
            Logger.getLogger(ChatHandler.class.getName()).log(Level.SEVERE, null, ex);
        }
     }
 
 
     public void run(){
     String line=null;
	synchronized(handlers) {
	    handlers.addElement(this);
 // add() not found in Vector class
	}
	try {
	    while(!(line = read.readLine()).equalsIgnoreCase("/q")) {
		for(int i = 0; i < handlers.size(); i++) {	
			synchronized(handlers) {
		            ChatHandler handler = (ChatHandler)handlers.elementAt(i);                        
                            handler.write.write(line);
                            handler.write.newLine();
                            handler.write.flush();
                            System.out.println(read.readLine()+"\r\n");
			}
		}
	    }
 
	} catch(IOException ioe) {
	    ioe.printStackTrace();
	} finally {
	    try {
		read.close();
		write.close();
		socket.close();
	    } catch(IOException ioe) {
	    } finally {
		synchronized(handlers) {
		    handlers.removeElement(this);
		}
	    }
	}
    }
}

And client code:
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;
 
/**
 *
 * @author Lolek
 */
public class Main {
 
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
       String addressIP;
       if (args.length == 0) {
                addressIP = "127.0.0.1";
            } 
       else {
                addressIP = args[0];
            }
       ReciveT recive = new ReciveT(addressIP,5000);
       SendT send = new SendT(recive.getSocket());
    }
 
}
 
class ReciveT implements Runnable
{
    private Socket socket;
    private String IPAddress;
    private int port;
 
    ReciveT(String IPAddress,int port)
    {   
        try {
            this.IPAddress = IPAddress;
            this.port = port;
            this.socket = new Socket(IPAddress, port);
            new Thread(this, "Recive thread").start();
        } catch (UnknownHostException ex) {
            Logger.getLogger(ReciveT.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(ReciveT.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    public Socket getSocket()
    {
        return this.socket;
    }
    public void run()
    {
        BufferedReader read = null;
        try {
            read = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            String line = null;
            while ((line = read.readLine()) != null) {
                System.out.println(line);
                System.out.flush();
            }
        } catch (IOException ex) {
            Logger.getLogger(ReciveT.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                read.close();
            } catch (IOException ex) {
                Logger.getLogger(ReciveT.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}
 
class SendT implements Runnable
{
    private Socket socket;
 
    SendT(Socket socket)
    {
        this.socket = socket;
        new Thread(this, "Send Thread").start();
    }
    public void run()
    {
        BufferedWriter write = null;
        try {
            BufferedReader readKeyboard = new BufferedReader(new InputStreamReader(System.in));
            write = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
 
            String line;
            while ((line = readKeyboard.readLine()) != null) {
                write.write(line);
                write.newLine();
                write.flush();
            }
        } catch (IOException ex) {
            Logger.getLogger(SendT.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                write.close();
            } catch (IOException ex) {
                Logger.getLogger(SendT.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}