-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclientNew.java
66 lines (53 loc) · 1.39 KB
/
clientNew.java
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
61
62
63
64
65
66
import java.io.*;
import java.net.*;
import java.util.*;
public class clientNew {
public static void main(String[] args) throws IOException {
new setUp2();
}
}
class setUp2 {
private final static int port = 9001;
private final static String host = "localhost";
private static Socket s;
public setUp2() throws IOException {
s = new Socket(host, port);
new Thread(new reply()).start();
new Thread(new listen()).start();
}
public static Socket getS() {
return s;
}
}
class reply implements Runnable {
public reply() {
}
@Override
public void run() {
try (Scanner commands = new Scanner(System.in)) {
try (PrintWriter writer = new PrintWriter(setUp2.getS().getOutputStream(), true)) {
while (true) {
writer.println(commands.nextLine());
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
class listen implements Runnable {
public listen() {
}
@Override
public void run() {
try {
try (Scanner reader = new Scanner(setUp2.getS().getInputStream())) {
while (true) {
System.out.println(reader.nextLine());
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}