-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaxCharClient.java
More file actions
38 lines (29 loc) · 1.32 KB
/
MaxCharClient.java
File metadata and controls
38 lines (29 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import java.io.*;
import java.net.*;
import java.util.Scanner;
class MaxCharClient {
public static void main(String argv[]) throws Exception {
Scanner scanner = new Scanner(System.in);
Socket clientSocket = new Socket("localhost", 6789);
System.out.println("Client running, connected to server.");
DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
while (true) {
System.out.print("Enter a string (or type No to exit): ");
String sentence = scanner.nextLine();
System.out.println("Writing to socket...");
outToServer.writeBytes(sentence + '\n');
if (sentence.equalsIgnoreCase("No")) {
break;
}
System.out.println("Reading from socket...");
String response = inFromServer.readLine();
System.out.println("Most frequent character: " + response);
// Receiving the server's continuation message
String serverMessage = inFromServer.readLine();
System.out.println(serverMessage);
}
clientSocket.close();
scanner.close();
}
}