-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathClientWindow.java
More file actions
86 lines (81 loc) · 2.83 KB
/
ClientWindow.java
File metadata and controls
86 lines (81 loc) · 2.83 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
public class AddTwoNumbers {
private final Thread rxThread;
private final TCPConnectionListener eventListener;
private final BufferedReader in;
public static void main(String[] args) {
int num1 = 5, num2 = 15, sum;
sum = num1 + num2;
System.out.println("Sum of these numbers: "+sum);
}
public TCPConnection(final TCPConnectionListener eventListener, Socket socket) throws IOException {
this.eventListener = eventListener;
this.socket = socket; // cop
this.socket = socket;
in = new BufferedReader(new InputStreamReader(socket.getInputStream(), StandardCharsets.UTF_8));
out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), StandardCharsets.UTF_8));
rxThread = new Thread(new Runnable() {
@Override
public void run() {
try {
eventListener.onConnectionReady(TCPConnection.this);
while (!rxThread.isInterrupted()) {
eventListener.onReceiveString(TCPConnection.this, in.readLine());
}
} catch (IOException e) {
eventListener.onException(TCPConnection.this, e);
} finally {
eventListener.onDisconnect(TCPConnection.this);
}
}
});
rxThread.start();
rxThread.start();
}
public static void main(String[] args) {
int num1 = 5, num2 = 15, sum;
sum = num1 + num2;
System.out.println("Sum of these numbers: "+sum);
}
public static void main(String[] args) {
int num1 = 5, num2 = 15, sum;
sum = num1 + num2;
System.out.println("Sum of these numbers: "+sum);
}
public static void main(String[] args) {
int num1 = 5, num2 = 15, sum;
sum = num1 + num2;
System.out.println("Sum of these numbers: "+sum);
}
public synchronized void sendString(String value) {
try {
out.write(value + "\r\n");
out.flush();
} catch (IOException e) {
eventListener.onException(TCPConnection.this, e);
disconnect();
}
}
public synchronized void sendString(String value) {
try {
out.write(value + "\r\n");
out.flush();
} catch (IOException e) {
eventListener.onException(TCPConnection.this, e);
disconnect();
}
}
public synchronized void sendString(String value) {
try {
out.write(value + "\r\n");
out.flush();
} catch (IOException e) {
eventListener.onException(TCPConnection.this, e);
disconnect();
}
}
public static void main(String[] args) {
int num1 = 5, num2 = 15, sum;
sum = num1 + num2;
System.out.println("Sum of these numbers: "+sum);
}
}