pablohf

client

Sep 25th, 2012
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.31 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package dailyadviceclient;
  6.  
  7. /**
  8.  *
  9.  * @author pablo
  10.  */
  11. public class DailyAdviceClient {
  12.  
  13.     /**
  14.      * @param args the command line arguments
  15.      */
  16.     public static void main(String[] args) {
  17.         Client client;
  18.         client = new Client();
  19.  
  20.         client.go();
  21.  
  22.     }
  23. }
  24. \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\//\/\/\/\/\/\/\/\/\/\/////////////////////////////
  25. /*
  26.  * To change this template, choose Tools | Templates
  27.  * and open the template in the editor.
  28.  */
  29. package dailyadviceclient;
  30.  
  31. import java.io.BufferedReader;
  32. import java.io.IOException;
  33. import java.io.InputStreamReader;
  34. import java.net.Socket;
  35.  
  36. /**
  37.  *
  38.  * @author pablo
  39.  */
  40. public class Client {
  41.  
  42.     public Client(){
  43.     }
  44.  
  45.     public void go() {
  46.         try {
  47.             Socket s;
  48.             s = new Socket("127.0.0.1", 4242);
  49.  
  50.             InputStreamReader streamReader = new InputStreamReader(s.getInputStream());
  51.             try (BufferedReader reader = new BufferedReader(streamReader)) {
  52.                 String advice;
  53.                 advice = reader.readLine();
  54.                 System.out.println("Today you should: " + advice);
  55.             }
  56.  
  57.         } catch (IOException ex) {
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment