Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.apache.commons.io.input.ReversedLinesFileReader;
- import java.io.IOException;
- import java.util.*;
- import java.net.*;
- import java.io.*;
- import javax.swing.Timer;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- public class FixedMessageSequenceClient {
- static String KKJokes[] = { "Permission granted." , "What is Alabama population", "y", //00
- "Permission granted." , "What is Alaska population", "y", //01
- "Permission granted." , "What is Arizona population", "y", //02
- "Permission granted." , "What is Arkansas population", "y", //03
- "Permission granted." , "What is California population", "y", //04
- "Permission granted." , "What is Colorado population", "y", //05
- "Permission granted." , "What is Connecticutt population", "y", //06
- "Permission granted." , "What is Delaware population", "y", // 7
- "Permission granted." , "What is Florida population", "y", // 8
- "Permission granted." , "What is Georgia population", "y", // 9
- "Permission granted." , "What is Hawaii population", "y", // 10
- "Permission granted." , "What is Idaho population", "y", // 11
- "Permission granted." , "What is Illinois population", "y", // 12
- "Permission granted." , "What is Indiana population", "y", // 13
- "Permission granted." , "What is Iowa population", "y", // 14
- "Permission granted." , "What is Kansas population", "y", // 15
- "Permission granted." , "What is Kentucky population", "y", //16
- "Permission granted." , "What is Louisiana population", "y", //17
- "Permission granted." , "What is Maine population", "y", //18
- "Permission granted." , "What is Maryland population", "y", //19
- "Permission granted." , "What is Massachusetts population", "y", //20
- "Permission granted." , "What is Michigan population", "y", //21
- "Permission granted." , "What is Minnesota population", "y", //22
- "Permission granted." , "What is Mississippi population", "y", //23
- "Permission granted." , "What is Missouri population", "y", //24
- "Permission granted." , "What is Montana population", "y", //25
- "Permission granted." , "What is Nebraska population", "y", //26
- "Permission granted." , "What is Nevada population", "y", //27
- "Permission granted." , "What is New Hampshire population", "y", //28
- "Permission granted." , "What is New Jersey population", "y", //29
- "Permission granted." , "What is New Mexico population", "y", //30
- "Permission granted." , "What is New York population", "y", //31
- "Permission granted." , "What is North Carolina population", "y", //32
- "Permission granted." , "What is North Dakota population", "y", //33
- "Permission granted." , "What is Ohio population", "y", //34
- "Permission granted." , "What is Oklahoma population", "y", //35
- "Permission granted." , "What is Oregon population", "y", //36
- "Permission granted." , "What is Pennsylvania population", "y", //37
- "Permission granted." , "What is Rhode Island population", "y", //38
- "Permission granted." , "What is South Carolina population", "y", //39
- "Permission granted." , "What is South Dakota population", "y", //40
- "Permission granted." , "What is Tennessee population", "y", //41
- "Permission granted." , "What is Texas population", "y", //42
- "Permission granted." , "What is Utah population", "y", //43
- "Permission granted." , "What is Vermont population", "y", //44
- "Permission granted." , "What is Virginia population", "y", //45
- "Permission granted." , "What is Washington population", "y", //46
- "Permission granted." , "What is West Virginia population", "y", //47
- "Permission granted." , "What is Wisconsin population", "y", //48
- "Permission granted." , "What is Wyoming population", "y" /* 49 */
- };
- public static void main(String[] args ) throws IOException {
- String lastNumString = returnLastNumber();
- int lastNum = Integer.parseInt(lastNumString );
- int modlastNum = lastNum ;
- if (modlastNum != 0) {
- modlastNum += 1; // starting to start at next state
- modlastNum*=3; //because there are 3 phrases per state
- }
- System.out.println( " Last position in file is " + lastNum + ". AND kkjokes.length " + KKJokes.length
- + "\n and modlastNum is " + modlastNum);
- Socket kkSocket = null;
- PrintWriter out = null;
- BufferedReader br = null;
- try {
- kkSocket = new Socket("localhost", 4444);
- out = new PrintWriter(kkSocket.getOutputStream(), true);
- br = new BufferedReader( new InputStreamReader ( kkSocket.getInputStream() ));
- for (int i = modlastNum; i < KKJokes.length ; i++){
- String fromServer = br.readLine();
- out.println(KKJokes[ i % KKJokes.length ]);
- if ( (i % 3 )==2){
- try {
- Thread.sleep(11);
- } catch (InterruptedException ie) {}
- }
- // fromServer = br.readLine(); System.out.println ( fromServer ); fromServer = br.readLine(); System.out.println ( fromServer ); // String fromServer3 = br.readLine(); System.out.println ( fromServer3 ) ; System.out.println ( fromServer ) ;
- if(fromServer.equals("inputOfYes")){
- while (!(fromServer.equals("nowlogged"))) {
- fromServer = br.readLine();
- }
- }
- System.out.println ( fromServer ) ;
- } // end-forLoop starting at Ln. 93
- out.println("Line 138 Client- Bye");
- System.out.println ("Line 139 Client - Bye" );
- out.close();
- kkSocket.close();
- } catch ( IOException io ){
- System.err.println("Calling IO . toString " + io.toString());
- System.exit(1);
- }
- }
- public static String returnLastNumber() {
- String lastLine = null;
- try {
- File someFile = new File("C:\\\\Java_Scratch3_new_cleaned_Mar12\\\\FixedMessageLog.txt");
- ReversedLinesFileReader reader = new ReversedLinesFileReader( someFile );
- lastLine = reader.readLine();
- if (lastLine == null){
- lastLine = "0";
- }
- }catch ( IOException ee) { }
- return lastLine;
- } //end function returnLastNumber()
- }// end class FixedMessageSequenceClient
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement