hello,

i have to write a chat application, which is capable to comunicate...one istance of the app will be used as server, and other will be used as clients...

that chat works fine, when only two people chat, but the problem is, when i connect with the third client...the program starts, but it doesnt communicate with others...the other two are still working, but this one looks like, it is connected with nooone, and all messages go to null

i think the problem is in threads ( i am new with threads )...i dont think i am using the smartly

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

public class vaja11
{

	public static void main(String [] arg) throws Exception
	{

		

	
		if( arg.length == 2)
		{
			
			new Povezava( arg[0], Integer.parseInt( arg[1] ) );

			/*while(true)
			{
				Thread.currentThread().sleep(100);
			}*/
		}
		else if( arg.length == 1)
		{

			int i=0; // flag

			ServerSocket ss = new ServerSocket ( Integer.parseInt( arg[0] ) );
			System.out.println( "Cakam na povezovo");

			while(true)
			{
				
				Socket s = ss.accept();
				i++;
				System.out.println( "Povezava sprejeta");

				if( i == 1)
				{
					new Povezava( s );
				}
			}
		}
	}
}

import java.net.*;
import java.io.*;

public class Povezava extends Thread{

	private String host;
	private int port;
	private Socket s;

	private Okno o;

	BufferedWriter bw;
	BufferedReader br;

	public Povezava(Socket s ){
				
		this.s = s;

		try
		{
		
			br = new BufferedReader( new InputStreamReader ( s.getInputStream() ) );
			bw = new BufferedWriter( new OutputStreamWriter ( s.getOutputStream() ) );
		
			o = new Okno( br, bw );
		}
		catch(Exception e){ e.printStackTrace(); }

		start();
	
	}

	public Povezava(String host, int port){
		
		this.host = host;
		this.port = port;

		try
		{
			s = new Socket( host, port );
           			
			br = new BufferedReader( new InputStreamReader ( s.getInputStream() ));
			bw = new BufferedWriter( new OutputStreamWriter ( s.getOutputStream() ));
		
			o = new Okno( br, bw );	
		}
		catch(Exception e){ e.printStackTrace(); }

		start();
	
	
	}

	public void run() 
	{

         // what to write here?
	}


}

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.net.*;

public class Okno extends JFrame implements Runnable{

	private BorderLayout b;
	
	private JPanel west;
	private JPanel east;
	private JPanel center;
	private JPanel south;
	private JPanel north;
	
	private Container c;
	
	private JButton btnIzhod;
	private GridBagConstraints btnIzhodOmejitve;
	
	private List lVsebina;
	private GridBagConstraints lVsebinaOmejitve;
	private JButton btnPoslji;
	private GridBagConstraints btnPosljiOmejitve;
	
	private JTextField jtfSporocilo;
	private GridBagConstraints jtfSporociloOmejitve;
			
	private BufferedReader vhod;
	private BufferedWriter izhod;
	
	private JMenuBar m;
	private JMenu moznosti;
	private JMenuItem naloziSliko;
	
	public Okno( BufferedReader br, BufferedWriter bw ){
		
		vhod = br;
		izhod = bw;

		
		initGradnikov();
		initSouth();
		initCenter();
		initEast();
							
		setTitle( "Komunikator" );
										
		setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE);
		
		c.setLayout( b );
		c.add( "Center", center );
		c.add( "South", south );
		c.add( "East", east );
		c.add( "West", west );
		c.add( "North", north );


		addMenu();	
		setSize( 400, 400);
		setVisible( true );

		// KONEC LAYOUTA
		
	
		btnPoslji.addActionListener( new ActionListener() {
			
			public void actionPerformed( ActionEvent ae){
				
				lVsebina.add( jtfSporocilo.getText() );
				
				try{
				
						izhod.write( jtfSporocilo.getText() + "\n" );
						izhod.flush();

					 }
				catch( IOException ie){ 
						ie.printStackTrace();
						System.exit(0); 
					}
				
				jtfSporocilo.setText("");
				
				}
				
			});

		btnIzhod.addActionListener( new ActionListener() {
		
			public void actionPerformed( ActionEvent ae ){
			
				System.exit(0);
			}


		});
		
		new Thread( this ).start();
		
	}
	
// important part
// thread is writing input stream to a list
	public void run(){
		
		while(true){
			
				try{
			
						String s= vhod.readLine();
						lVsebina.add( ":: "+s );
						
					 }
				catch(IOException ie){ 
						ie.printStackTrace();
						System.exit(0);	
					}
			
				}
			
		} // end Run()

	private void initGradnikov(){

		c = this.getContentPane();
	
		b = new BorderLayout();
					
		west = new JPanel();
		east = new JPanel();
		center = new JPanel();
		south = new JPanel();
		north = new JPanel();
		
		btnIzhod = new JButton( "Izhod" );
		btnIzhodOmejitve = new GridBagConstraints(1,1,1,1,1,1,GridBagConstraints.CENTER,
			GridBagConstraints.NONE, new Insets(1,1,1,1), 1,1);
	
		lVsebina = new List();
		lVsebinaOmejitve = new GridBagConstraints(1,1,1,1,1,1,GridBagConstraints.CENTER,
			GridBagConstraints.BOTH, new Insets(1,1,1,1), 1,1);
				
		btnPoslji = new JButton( "Poslji" );
		btnPosljiOmejitve = new GridBagConstraints(6,1,1,1,1,1,GridBagConstraints.CENTER,
			GridBagConstraints.BOTH, new Insets(1,1,1,1), 1,1);
		
		jtfSporocilo = new JTextField();
		jtfSporociloOmejitve = new GridBagConstraints(1,1,5,5,1,1,GridBagConstraints.CENTER,
			GridBagConstraints.BOTH, new Insets(1,1,1,1), 1,1);

		m = new JMenuBar();
		moznosti = new JMenu( "Moznosti" );
		
		naloziSliko = new JMenuItem( "NaloziSliko" );

	
	}

	private void initSouth(){
	
		south.setLayout( new GridBagLayout() );
		
		south.add ( btnIzhod, btnIzhodOmejitve );
	
	}

	private void initCenter(){

		center.setLayout( new BorderLayout() );
		
		JPanel spodaj = new JPanel();
		
		spodaj.setLayout( new GridBagLayout() );
	
		spodaj.add( jtfSporocilo, jtfSporociloOmejitve );
		spodaj.add( btnPoslji, btnPosljiOmejitve );
		
		JPanel list = new JPanel();
		
		list.setLayout( new GridBagLayout() );
		list.add ( lVsebina, lVsebinaOmejitve );
		
		
		center.add( "South", spodaj );
		center.add( "Center", list );
	
	
	}
// only design
	private void initEast(){

		JLabel slika = new JLabel();

		ImageIcon s = new ImageIcon ( "test.jpg" );

		slika.setIcon( s );

		east.add( slika );

	}

// unimportant
	private void addMenu(){
			
		moznosti.addActionListener(	new ActionListener(){
			
			public void actionPerformed(ActionEvent ae){
			
			
			}
		
		}
			
			);

		m.add( moznosti);
		setJMenuBar( m );

		moznosti.add( naloziSliko );
	
	}
btw. povezava means connection!