Hi, I'd like to ask for a little help. I have this program that handles basic voting,but it should be done client-server,i.e. the server offers questions and multiple clients connect to vote,the server stores the answers etc... I haven't even come to that point of storing etc.,cause I'm stuck here for a while. I do multiple sending and receiving of messages between the client and the server,e.g. server offers an initial menu to choose from 5 categories, the client chooses one,then I handle the choice using switch(),so I send the appropriate answer back. Since one of my answers is a multi-line menu, I should use a while((line = reader.readline()) != null) loop so I could get all the lines to present to the client, so that he could choose from the menu. And that's where the problem arises - I noticed that if I delete the while() loop and read only one line,everything is OK,I get the answer based on user's input. If I use the loop,the program gets stuck when the user inputs text,it doesn't do anything,doesn't even terminate or give me errors. So, my code is kind of big, I'm not so sure how to post it here,so I'll initially post the critical part only,an excerpt from the client-side code, assume that on the other side there is server-side handling using switch() and case. Here is the snippet. There's only one while() loop, so it won't be hard to spot it. Thanks a lot, regards
s = new Socket("127.0.0.1",8989);
/**Displaying the first question to the user*/
System.out.println("Choose a category please: \n 1.Rock bands \n 2.Rock guitarists \n 3.Rock albums \n 4.Hitchcock films \n 5.Actors ");
/** Getting input from the user*/
BufferedReader userEnteredText = new BufferedReader(new InputStreamReader(System.in));
String takenUserText = userEnteredText.readLine();
/**Sending the input to the server */
PrintWriter out = new PrintWriter(new OutputStreamWriter(s.getOutputStream()));
out.println(takenUserText);
out.flush();
//userEnteredText.close();
/**Getting the response from the server*/
BufferedReader reader = new BufferedReader(new InputStreamReader(s.getInputStream()));
String line;
while((line = reader.readLine()) != null){
System.out.println(line);
}
/**Getting another user input*/
BufferedReader userEnteredText1 = new BufferedReader(new InputStreamReader(System.in));
String takenUserText1 = userEnteredText1.readLine();
/**Sending the new user input back to the server*/
PrintWriter out1 = new PrintWriter(new OutputStreamWriter(s.getOutputStream()));
out1.println(takenUserText1);
out1.flush();
/**Reading the results from the server*/
BufferedReader reader1 = new BufferedReader(new InputStreamReader(s.getInputStream()));
String line1 = reader1.readLine();
System.out.println(line1);