/*FortuneClient.java*/
import java.io.*;
import java.net.*;
class FortuneClient
{
  public static void main(String args[])
  {
    FortuneClient client=new FortuneClient();
    System.out.println(client.getMessage());
  }
  public String getMessage()
  {
    String fortune;
    try
    {
      DatagramSocket socket;
      DatagramPacket packet;
      byte[] data=new byte[256];
      socket=new DatagramSocket();
      packet=new DatagramPacket(data,data.length,InetAddress.getByName("127.0.0.1"),1114);
      socket.send(packet);
      packet=new DatagramPacket(data,data.length);
      socket.receive(packet);
      fortune=new String(packet.getData(),0);
      socket.close();
    }
    catch(UnknownHostException e)
    {
      System.err.println("Exception:host could not be found");
      return null;
    } 
    catch(Exception e)
    {
      System.err.println("Exception:"+e);
      e.printStackTrace();
      return null;
    }
    return fortune;
  }
}
