-
Notifications
You must be signed in to change notification settings - Fork 0
/
Receiver.java
49 lines (37 loc) · 950 Bytes
/
Receiver.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
package chat;
import org.joda.time.DateTime;
import java.io.BufferedReader;
import java.io.IOException;
import java.net.Socket;
public class Receiver implements Runnable {
private Socket socket;
private BufferedReader socketReader;
volatile boolean shutdown = false;
public Receiver(Socket s,BufferedReader buf) throws IOException {
this.socket = s;
this.socketReader = buf;
}
public void shutdownReceiverThread() {
this.shutdown = true;
}
@Override
public void run() {
String msg;
while(!this.shutdown) {
try {
msg = socketReader.readLine();
if (msg == null) {
break;
}else {
if (msg.equals("PONG:" + Server.getExternalIp().toString())) {
HandleClients.clientStreams.get(socket).setActiveTime(DateTime.now());
}else {
HandleClients.message.add(socket.getRemoteSocketAddress() + " " + msg);
}
}
} catch (IOException e) {
break;
}
}
}
}