-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPeerBackground.java
More file actions
40 lines (30 loc) · 832 Bytes
/
PeerBackground.java
File metadata and controls
40 lines (30 loc) · 832 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
37
38
39
40
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
class PeerBackground implements Runnable {
private static ServerSocket listeningSocket = null;
PeerBackground(int portForCAN) throws IOException {
listeningSocket = new ServerSocket(portForCAN);
}
public void run() {
while (true) {
try {
Socket client = listeningSocket.accept();
// Start listening for CAN messages.
new Thread(new PeerWorker(client, Peer.portforCAN)).start();
} catch (Exception e) {
System.out.println(e.getMessage());
}
continue;
}
}
public static void stopListening() {
try {
System.out.println("Stopping monitoring in CAN.");
listeningSocket.close();
Thread.currentThread().interrupt();
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
}