-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient3.java
More file actions
37 lines (28 loc) · 925 Bytes
/
Copy pathClient3.java
File metadata and controls
37 lines (28 loc) · 925 Bytes
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
import java.io.*;
import java.net.*;
import java.util.Scanner;
public class Client3{
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
Socket s = new Socket("localhost", 6969);
DataInputStream in = new DataInputStream(s.getInputStream());
DataOutputStream out = new DataOutputStream(s.getOutputStream());
String fromserver;
String mode;
String fromuser;
while(true){
mode = in.readUTF();
if(mode.equals("break")) break;
fromserver = in.readUTF();
if(!fromserver.isEmpty())
System.out.println(fromserver);
if (mode.equals("write")) {
fromuser = sc.nextLine();
out.writeUTF(fromuser);
}
if (mode.equals("read")){}
}
sc.close();
s.close();
}
}