-
Notifications
You must be signed in to change notification settings - Fork 0
/
ListeningThread.java
52 lines (46 loc) · 1.03 KB
/
ListeningThread.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
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
public class ListeningThread implements Runnable
{
private ServerSocket SocketListening;
private String peerID;
Socket remoteSocket;
Thread sendingThread;
public ListeningThread(ServerSocket socket, String peerID)
{
this.SocketListening = socket;
this.peerID = peerID;
}
public void run()
{
while(true)
{
try
{
remoteSocket = SocketListening.accept();
// instantiates thread for handling individual remote peer
sendingThread = new Thread(new RemotePeerHandler(remoteSocket,0,peerID));
peerProcess.showLog(peerID + " Connection is established");
peerProcess.sendingThread.add(sendingThread);
sendingThread.start();
}
catch(Exception e)
{
peerProcess.showLog(this.peerID + " Exception in connection: " + e.toString());
}
}
}
public void releaseSocket()
{
try
{
if(!remoteSocket.isClosed())
remoteSocket.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}