-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.java
More file actions
34 lines (27 loc) · 1.01 KB
/
Copy pathclient.java
File metadata and controls
34 lines (27 loc) · 1.01 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
import java.io.*;
import java.net.*;
import java.util.Scanner;
public class client {
public static void main(String[] args) {
try (Socket socket = new Socket("localhost", 12345)) {
System.out.println("Connected to the server");
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
PrintWriter output = new PrintWriter(socket.getOutputStream(), true);
Scanner scanner = new Scanner(System.in);
String message;
while (true) {
System.out.print("You: ");
message = scanner.nextLine();
output.println(message);
if ("bye".equalsIgnoreCase(message)) {
System.out.println("Disconnected from the server");
break;
}
System.out.println(input.readLine());
}
scanner.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}