Socket s = new Socket("localhost", SBAP_PORT);
InputStream instream = s.getInputStream();
OutputStream outstream = s.getOutputStream();
Scanner in = new Scanner(instream);
PrintWriter out = new PrintWriter(outstream);
ArrayList<String> wordList = new ArrayList<String>();
// Creates a scanner to read input from the keyboard
Scanner input = new Scanner(System.in);
// instantiates a string for use with the input from the user
String command = "";
// While connected is true, then prompt the user to send words to the server
System.out.println("Type in a word to send to the server.");
// Sends the word to the server from the TextField
System.out.print("Sending: " + component.text() + "\n");
out.println(component.text());
out.flush();
// gets the Response from the server
response = in.nextLine();
if(!response.equals("Word does not exist"))
{
wordList.add(response);
System.out.println("Receiving: " + response + "\n");
}
for(String str: wordList)
{
System.out.println(wordCount);
wordCount++;
}
Everything underneith //While connected is true...
Is what I want to have loop infinitely, however, I want it to loop back through, and wait for the user to input again before continuing.
As it is now, if I have a while{ ... } loop around all that, it keeps adding the response to the wordList ArrayList, and since it continues to repeat that, wordCount continues to increase also.
I'm still currently trying to think of a way to get this loop to halt and wait before continuing. Google searches for making a loop wait kept bringing up threading and using wait() and notify() on threads... and this is not a threading issue, lol.
Thank you for your time.