salve a tutti sto sviluppando una chat in java con possibilità di scambio messaggi oltre che pubblici anche privati.

La chat funziona come segue:

c'è una finestra in cui il partecipante alla chat si collega inserendo il proprio nome utente, dopodichè tale nome viene inserito in una lista di tutti gli utenti connessi in chat pubblica.

Nel momento in cui un utente volesse iniziare una chat privata con un altro utente, basta che clicchi sul relativo nome all'interno della lsita degli utenti connessi e si aprono altre 2 finestre per poter per mettere ai 2 utenti la comunicazione tra di loro.

Lato client ho i seguenti metodi :

codice:
package chatApplet;

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

/**
 * Classe che implementa l'invio e la ricezione dei messaggi Client
 *
 * 
 */

public class ClientChat
{
   private DataOutputStream os;
   private BufferedReader is;
   private DataOutputStream os_PVT;
   private BufferedReader is_PVT;
   private Socket socket;
   private Socket sockPVT;

   /**
    * Metodo per la connessione client al server
    * @throws UnknownHostException
    * @throws IOException
    * @throws ConnectException
    */

   public void start() throws UnknownHostException,IOException,ConnectException
   {

     try{
            Socket sock=new Socket();
            sock.connect(new InetSocketAddress("127.0.0.1",7777));

            //Stream di byte da passare al Socket
            os = new DataOutputStream(sock.getOutputStream());
            is = new BufferedReader(new InputStreamReader(sock.getInputStream()));
        }
     catch(Exception e){

     }
   }

   public void startPVT() throws UnknownHostException,IOException,ConnectException
   {

     try{
           Socket SockPVT=new Socket();
           SockPVT.connect(new InetSocketAddress("127.0.0.1",7777));

          //Stream di byte da passare al Socket
          os_PVT = new DataOutputStream(SockPVT.getOutputStream());
          is_PVT = new BufferedReader(new InputStreamReader(SockPVT.getInputStream()));

        }
     catch(Exception e){

     }
   }

   /**
    * Metodo per l'invio del messaggio
    *
    * @param strMessage Testo contenente il messaggio
    * @throws IOException
    * @throws NullPointerException
    */

   public void inviaMessaggio(String strMessage) throws IOException,
           NullPointerException
   {
        try{
            os.writeBytes(strMessage + '\n');
        }
        catch(Exception e){

        }
   }

   public void inviaPVT(String strPVT) throws IOException, NullPointerException
   {
        try
        {
           os_PVT.writeBytes(strPVT + '\n');
        }
        catch(Exception pvt)
        {

        }
   }

   /**
    * Metodo per la ricezione del messaggio
    * @return restituisce il messaggio appena ricevuto
    * @throws IOException
    */

    public String MessaggiRicevuti() throws IOException
   {
      try
      {
         return is.readLine();
     }
      catch(NullPointerException e)
      {
          return "";
      }
    }

    /**
     *
     * @return
     * @throws IOException
     */
    public String MessaggiPVTRicevuti() throws IOException
    {
        return is_PVT.readLine();
    }

   /**
    * Metodo che chiude tutti i flussi stream e la Socket
    * @throws IOException
    * @throws NullPointerException
    */

   public void close() throws IOException,NullPointerException
   {
      System.out.println("Chiusura client");
      os.close();
      System.out.println("Chiusura stream os");
      is.close();
      System.out.println("Chiusura stream is");
      socket.close();
      System.out.println("Chiusura socket");
   }

   public void closePVT() throws IOException,NullPointerException
   {
      System.out.println("Chiusura client privato");
      os_PVT.close();
      System.out.println("Chiusura stream ospvt");
      is_PVT.close();
      System.out.println("Chiusura stream ispvt");
      try
      {
          sockPVT.close();
          System.out.println("Chiusura socket");
       }
      catch(NullPointerException ex)
      {
          System.out.println("");
      }
   }
}