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.

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);

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

	while(true) {
        public void run()                       
          try {//starts try 1


while(numbers > 0){

	  	input = new DataInputStream(income.getInputStream());
   	 output = new PrintStream(income.getOutputStream());
   	 String bye = "bye1";
   	 String read = input.readLine();
   	  if (read == null){
	//ends try
	catch(IOException 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.