create a server program on web server,in applet.init(), applet listen on a port,send a message(to tell server its port number) to server, server keep the IP,port pair.
so server can send udp packet with the ip,port pair.
applet is both udp server and udp client.
import java.net.*;
import java.io.*;public class Server{
    public static void main( String[] args ){
        DatagramSocket socket = null;
        DatagramPacket packet = null;
        byte[] buf = new byte[256];
        InetAddress address;
        int port;
        try{            
            socket = new DatagramSocket(2000);
        }catch( SocketException e ){
            System.err.println( e.getMessage() );
        }        try{
            
            packet = new DatagramPacket( buf, 256 );
            socket.receive( packet );
            address = packet.getAddress();
            port    = packet.getPort();
            String msg = new String( packet.getData(),0 );
            System.out.println("recieve from client--" );
            System.out.println(msg);
            String str = "I'm fine, thank you";
            str.getBytes( 0, str.length(), buf,0 );
            packet = new DatagramPacket( buf,buf.length, address, port );
            System.out.println("send msg to client--" );
            socket.send(packet);
            socket.close();
        }catch( IOException e ){
            e.printStackTrace();
        }
    }
}
import java.net.*;
import java.io.*;
 
public class Client{
    public static void main( String[] args ){
        DatagramSocket socket = null;
        DatagramPacket packet =null;
        byte[] buf = new byte[256];
        InetAddress address;
        try{
            socket = new DatagramSocket();
        }catch( java.net.SocketException e ){
            e.getMessage();
        }        try{
            String str = "How are you, Server?";
            str.getBytes( 0, str.length(), buf,0 );
            String host="localhost";
            if( args.length == 1 ){
                host = args[0];
            }
            address = InetAddress.getByName( host );
            packet  = new DatagramPacket(buf,buf.length,address, 2000 );
            System.out.println("send msg to Server---");
            socket.send( packet );
            packet = new DatagramPacket( buf,256 );
            socket.receive( packet );
            String msg = new String( packet.getData(),0 );
            System.out.println("recieve from Server--");
            System.out.println(msg);
            socket.close();
         }catch( IOException e ){
            System.out.println(e.getMessage());
            e.printStackTrace();
         }
    }
}