Advertisement
Guest User

FixedMessageSequenceClient

a guest
Oct 4th, 2015
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. import java.net.*;
  2. import java.io.*;
  3. import java.util.*;
  4.  
  5.  
  6. import org.slf4j.Logger;
  7. import org.slf4j.LoggerFactory;
  8. import java.sql.Timestamp;
  9. import java.util.Date;
  10.  
  11. public class FixedMessageSequenceClient {
  12.  
  13.  
  14. private static final Logger logger = LoggerFactory.getLogger("FixedMessageSequenceClient");
  15.  
  16. // private static Logger LOGGER = Logger.getLogger("InfoLogging");
  17.  
  18. static String KKJokes[] = { "Who's there?", "Turnip who?", "y",
  19. "Who's there?", "Little Old Lady who?", "y",
  20. "Who's there?" , "Doctor who?", "y",
  21. "Who's there?", "Teacher who?", "y",
  22. "Who's there", "Dog who?", "y",
  23. "Who's there?", "Firefighter who?", "y",
  24. "Who's there?", "Zoologist who?", "y",
  25. "Who's there?", "Atch who?", "y",
  26. "Who's there?", "Who who", "y",
  27. "Who's there?", "Who who", "y"};
  28.  
  29. // "Turnip", "Little Old Lady", "Doctor", "Teacher", "Dog", "Firefighter", "Zoologist", "Atch", "Who", "Who" };
  30.  
  31.  
  32. public static void main(String[] args) throws IOException {
  33.  
  34. logger.debug("This is a DEBUG message in Client-Side");
  35.  
  36.  
  37.  
  38. int startPosition = 0;
  39.  
  40. try {
  41. Scanner scan = new Scanner(new File ("somenumber.txt"));
  42.  
  43. while(scan.hasNext()) {
  44. startPosition = Integer.parseInt(scan.nextLine());
  45. System.out.println("The start position is : " + startPosition + "! ");
  46. }
  47.  
  48. } catch (Exception io) {}
  49.  
  50. Socket kkSocket = null;
  51. PrintWriter out = null;
  52. BufferedReader br = null;
  53.  
  54. try {
  55. kkSocket = new Socket("localhost", 4444);
  56. out = new PrintWriter(kkSocket.getOutputStream(), true);
  57. br = new BufferedReader( new InputStreamReader ( kkSocket.getInputStream() ));
  58.  
  59. for (int i = startPosition; i < KKJokes.length ; i++) {
  60. try {
  61. Thread.sleep(1000); /* was 1200*/ }
  62. catch(Exception e){
  63. e.printStackTrace();
  64. }
  65. //System.out.println ( "The kk jokes length is : " + KKJokes[i % KKJokes.length ] + ", and i is " + i + "." );
  66. out.println(KKJokes[i % KKJokes.length ]);
  67. String fromServer = br.readLine();
  68. System.out.println ( fromServer ) ;
  69. }
  70.  
  71. out.println("Bye");
  72.  
  73. System.out.println ("Bye" );
  74.  
  75. out.close();
  76. kkSocket.close();
  77. } catch ( IOException io ){
  78. System.err.println("Calling IO . toString " + io.toString()); //System
  79. System.exit(1);
  80. }
  81.  
  82.  
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement