Hello,Im making a chat program and so far ive programmed the client and the server.Unfortunately my server can only recive messages and send it too only 1 client at a time,so for example:
1.Client1 connects to the server.
2.Client1 types a message and clicks send
3.The server recives the message and sends it back to the chat text area to Client1 with Client1's name.
4.Client2 Connects types a message and clicks send.
5.Client2 Never gets a reply from the server(even though it is connected to the server).
6.When Client1 dissconectes from the server and client2 is the only one connected it gets a reply.

Can someone solve this problem for me so everyone can talk to the server and the server outputs all the mesages to all the client at once.

My current code for the server is:By the way run() is what handles all the messages at sends them.

Code:
import java.net.*;
import java.io.*;
import javax.swing.*;
import java.lang.*;


public class server implements Runnable {
	ServerSocket server;
	Socket income;
		 DataInputStream input;
		  PrintStream output;
		  Thread t;	
		  
		 int numbers = 1; //number of clients connected
		  
	
	
	public void init()	
	{	
		t=new Thread(this);
		t.start();
	}

	
	
	public server() {
		
		
		try {
		
		server = new ServerSocket(4001);
		
	}catch(IOException ff){
	}
	try {
		while(true){
		
		income = server.accept();
		run();
		numbers = 1;
		
		}
	}catch(IOException ee){
	}
	

	//Counter.start();
	while(true) {
	
	}
	}
	
	
	
            
        public void run()                       
        {              
          try {//starts try 1

	


while(numbers > 0){

	  	input = new DataInputStream(income.getInputStream());
   	 output = new PrintStream(income.getOutputStream());
   	 
   	 output.flush();
   	 String bye = "bye1";
   	 String read = input.readLine();
   	  if (read == null){
   	 	numbers--;
   	 	System.out.println("DISCONECTED");
   	 }
   	 System.out.println(read);
   	 output.println(read);
   	
   	 
   	 
   	 t.sleep(10);
		
	
	//ends try
	
	}
	}
	catch(IOException e){
		System.out.println(e);
	}catch(InterruptedException gg){
	}
	}
        

	
	
	
	public static void main(String[] args){
		server app = new server();
	}
}
Thanks.So you don't get confused the thread t does not really do nothing.