Hallo,
How can I do simple chat if I want to use SSL? I wrote some code but I donīt know if code is right. I donīt have experience with this stuff. I did just UDP chat. OK my code:
Java Code:
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.net.ssl.SSLServerSocket;
import javax.net.ssl.SSLServerSocketFactory;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;

/**
 * SslReverseEchoer.java
 * Copyright (c) 2005 by Dr. Herong Yang
 */

public class Main {
   public static void main(String[] args) {
       String adresaIP;
       if(args.length==0)
       {
            adresaIP="127.0.0.1";
       }
       else
       {
           adresaIP=args[0];
       }
      PrijimaciVlakno prijmout = new PrijimaciVlakno();
      OdesilaciVlakno odeslat = new OdesilaciVlakno(adresaIP);
     
      prijmout.prijimaci.start();
      odeslat.prijimaci.start();
   } 
}

class PrijimaciVlakno implements Runnable
{   Thread prijimaci; 
    
    public PrijimaciVlakno()
    {
        prijimaci = new Thread(this,"Prijimaci vlakno");
    }
    public void run()
    {
        try {
            SSLServerSocketFactory sslFactory = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
            SSLServerSocket sslServer = (SSLServerSocket) sslFactory.createServerSocket(5000);
            SSLSocket ssl = (SSLSocket) sslServer.accept();
            System.out.println("Adresa hostitele:"+ssl.getInetAddress().getHostName());
            
            while(true){
                
                BufferedReader cteniZeSocketu = new BufferedReader(new InputStreamReader(ssl.getInputStream()));
                String radek = null;
                while((radek = cteniZeSocketu.readLine())!=null)
                {
                    System.out.println("Prijata data:"+radek);
                    System.out.flush();
                }
            }
        
        } catch (IOException ex) {
            
        }
    }
}

class OdesilaciVlakno implements Runnable
{   Thread prijimaci;
    private String adresaIP;
    public OdesilaciVlakno(String ip)
    {
        this.adresaIP=ip;
        prijimaci = new Thread(this,"Prijimaci vlakno");
    }
    public void run()
    {   
        try {
            SSLSocketFactory sslFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
            SSLSocket ssl = (SSLSocket) sslFactory.createSocket(this.adresaIP,5000);
            
            BufferedReader klavesnice = new BufferedReader(new InputStreamReader(System.in));
            
            OutputStream vystupniProud = ssl.getOutputStream();
            BufferedWriter zapisDoSocketu = new BufferedWriter(new OutputStreamWriter(vystupniProud));
            
            String radek = null;
            while((radek = klavesnice.readLine())!=null)
            {
                zapisDoSocketu.write(radek+'\n');
                zapisDoSocketu.flush();
                System.out.println("Posilana data:"+radek);
            }
        } catch (IOException ex) {
            Logger.getLogger(OdesilaciVlakno.class.getName()).log(Level.SEVERE, null, ex);
        } 
    }
}