FileDocCategorySizeDatePackage
DailyAdviceServer.javaAPI DocExample1206Sat Jan 08 12:06:56 GMT 2005None

DailyAdviceServer

public class DailyAdviceServer extends Object

Fields Summary
String[]
adviceList
Constructors Summary
Methods Summary
private java.lang.StringgetAdvice()

      int random = (int) (Math.random() * adviceList.length);
      return adviceList[random];
   
public voidgo()

        try {
           ServerSocket serverSock = new ServerSocket(4200);
           
           while(true) {
              Socket sock = serverSock.accept();
              
              PrintWriter writer = new PrintWriter(sock.getOutputStream());
              String advice = getAdvice();
              writer.println(advice);              
              writer.close();  // must have THIS or flush() or it never writes...

              System.out.println(advice);
             }
        } catch(IOException ex) {
           ex.printStackTrace();
        }
     
public static voidmain(java.lang.String[] args)


         
       DailyAdviceServer server = new DailyAdviceServer();
       server.go();