Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.net.*;
- import java.io.*;
- import java.util.*;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import java.sql.Timestamp;
- import java.util.Date;
- public class FixedMessageSequenceClient {
- private static final Logger logger = LoggerFactory.getLogger("FixedMessageSequenceClient");
- // private static Logger LOGGER = Logger.getLogger("InfoLogging");
- static String KKJokes[] = { "Who's there?", "Turnip who?", "y",
- "Who's there?", "Little Old Lady who?", "y",
- "Who's there?" , "Doctor who?", "y",
- "Who's there?", "Teacher who?", "y",
- "Who's there", "Dog who?", "y",
- "Who's there?", "Firefighter who?", "y",
- "Who's there?", "Zoologist who?", "y",
- "Who's there?", "Atch who?", "y",
- "Who's there?", "Who who", "y",
- "Who's there?", "Who who", "y"};
- // "Turnip", "Little Old Lady", "Doctor", "Teacher", "Dog", "Firefighter", "Zoologist", "Atch", "Who", "Who" };
- public static void main(String[] args) throws IOException {
- logger.debug("This is a DEBUG message in Client-Side");
- int startPosition = 0;
- try {
- Scanner scan = new Scanner(new File ("somenumber.txt"));
- while(scan.hasNext()) {
- startPosition = Integer.parseInt(scan.nextLine());
- System.out.println("The start position is : " + startPosition + "! ");
- }
- } catch (Exception io) {}
- 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 = startPosition; i < KKJokes.length ; i++) {
- try {
- Thread.sleep(1000); /* was 1200*/ }
- catch(Exception e){
- e.printStackTrace();
- }
- //System.out.println ( "The kk jokes length is : " + KKJokes[i % KKJokes.length ] + ", and i is " + i + "." );
- out.println(KKJokes[i % KKJokes.length ]);
- String fromServer = br.readLine();
- System.out.println ( fromServer ) ;
- }
- out.println("Bye");
- System.out.println ("Bye" );
- out.close();
- kkSocket.close();
- } catch ( IOException io ){
- System.err.println("Calling IO . toString " + io.toString()); //System
- System.exit(1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement