-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnectionsListenerThread.java
More file actions
32 lines (27 loc) · 934 Bytes
/
ConnectionsListenerThread.java
File metadata and controls
32 lines (27 loc) · 934 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
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
/**
* This thread will listen for new connection requests
*/
public class ConnectionsListenerThread implements Runnable{
private ServerSocket serverSocket;
private int noOfConnections;
public ConnectionsListenerThread(ServerSocket serverSocket, int noOfConnections){
this.serverSocket = serverSocket;
this.noOfConnections = noOfConnections;
}
@Override
public void run() {
while(noOfConnections-- > 0){
try {
Socket newConnection = serverSocket.accept();
Thread thread = new Thread(new PeerMessageListenerThread(newConnection, true));
PeerApplication.addListenerThread(thread);
thread.start();
} catch (IOException ioException) {
ioException.printStackTrace();
}
}
}
}