-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.java
More file actions
60 lines (45 loc) · 2.07 KB
/
Copy pathClient.java
File metadata and controls
60 lines (45 loc) · 2.07 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.util.Scanner;
public class Client {
public static void main(String[] args) {
try {
InetAddress host = InetAddress.getLocalHost();
Socket socket = new Socket(host.getHostName(), 4123);
DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
DataInputStream dis = new DataInputStream(socket.getInputStream());
Scanner sc = new Scanner(System.in);
System.out.print("Enter Dictionary Keywords (separated by space): ");
String keywords = sc.nextLine();
System.out.print("Enter Word Length: ");
int wordLength = sc.nextInt();
sc.nextLine();
System.out.print("Enter File Path for Dictionary Generation (or press Enter for default): ");
String filePath = sc.nextLine();
if (filePath.isEmpty()) {
filePath = "default_path.txt";
}
System.out.print("Enter Number of Words to Generate: ");
int numberOfWords = sc.nextInt();
System.out.println("\n===== CLIENT INPUT SUMMARY =====");
System.out.println("| Keywords : " + keywords);
System.out.println("| Word Length : " + wordLength);
System.out.println("| File Path : " + filePath);
System.out.println("| No. of Words : " + numberOfWords);
System.out.println("===============================");
String message = keywords + "\n" + wordLength + "\n" + filePath + "\n" + numberOfWords;
dos.writeUTF(message);
dos.flush();
String confirmation = dis.readUTF();
System.out.println("\nServer Confirmation: " + confirmation);
dos.close();
dis.close();
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}