When I run the following code it stops to let me enter servername and them port number, after that it is supposed to stop and let me enter username but it never pauses for scan.nextline() and flies straight to enter reciever name??
public static void main(String[] args) throws IOException {
try {
System.out.println("
TCP Chat Client
Enter server name:");
Scanner scan = new Scanner(System.in);
//get server info from user
serverName = scan.nextLine();
System.out.println("
Enter port number:");
serverPort = scan.nextInt();
System.out.println("Enter your username:
");
userName = scan.nextLine();
//make connection to server
cSocket = new Socket(serverName, serverPort);
out = new PrintWriter(cSocket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(cSocket.getInputStream()));
//send username to server
out.println(userName);
String rcvrname="wefwef";
String message=null;
//start messaging
while(!(rcvrname.equals("exit"))){
System.out.println("Enter reciever name");
out.println(scan.nextLine());
System.out.println("Enter message");
out.println(scan.nextLine());
}
out.close();
in.close();
cSocket.close();
}
See Question&Answers more detail:os