-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProxyThread.java
43 lines (40 loc) · 1.22 KB
/
ProxyThread.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
import java.net.ServerSocket;
import java.net.Socket;
import java.io.IOException;
public class ProxyThread extends Thread
{
Cache cache;
private int porta;
/*
* Recebe os dados necessario para iniciar uma thread na porta certa
*/
public ProxyThread(int porta, Cache cache)
{
this.porta = porta;
this.cache = cache;
start();
}
/*
* Esse método recebe o ip da mquina que lhe esta a pedir informações.
* E depois inicia outro thread para receber mais pedido.
*/
public void run() {
try {
System.out.println("Servidor Proxy na porta : " + porta);
ServerSocket server = new ServerSocket(porta);
while (!interrupted()) {
Socket cliente = server.accept();
//System.out.println("Pedido do cliente com ip : " + cliente.getInetAddress());
new ProxyClientThread(cliente, cache);
sleep(5);
}
System.out.println("Stop");
}
catch (IOException e) {
System.out.println("Erreur MAIN : " + e);
}
catch (InterruptedException e) {
System.out.println("Erreur MAIN : " + e);
}
}
}