-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServidor
103 lines (84 loc) · 2.78 KB
/
Servidor
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package socius.dispositivos;
import aasocius2.PrincipalControllerThread;
import aasocius2.principalController;
import java.net.URL;
import socius.adapter.Arquivo;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import socius.stream.Transferencia;
/**
*
* @author Ana
*/
public class Servidor extends UnicastRemoteObject implements Transferencia{
private List<String> clientes=new ArrayList<String>();
private String host,mensagem;
private List<Arquivo> arquivos=new ArrayList<Arquivo>();
private List<URL> urls=new ArrayList<>();
public Servidor()throws RemoteException {
}
public void escutar() throws Exception {
try {
LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
//cria um objeto remoto
Servidor servidor=new Servidor();
//setar a instancia corrente
Naming.rebind("Compartilha",servidor);
System.out.println("Servidor Aberto e Operante!");
for(int i=0;i<servidor.getClientes().size();i++){
System.out.println("Conectados"+servidor.getClientes().get(i));
}
} catch (RemoteException ex) {
Logger.getLogger(Servidor.class.getName()).log(Level.SEVERE, null, ex);
}
}
public List<String> getClientes() {
return clientes;
}
@Override
public void iniciar(Computador origem, Computador destino, Arquivo arquivo) throws RemoteException {
}
@Override
public List<Arquivo> getlista() throws RemoteException {
return this.arquivos;
}
@Override
public void setmensagemServidor(String msg) {
mensagem=msg;
}
@Override
public String getmensagemServidor() {
return mensagem;
}
@Override
public String host() throws RemoteException {
return host;
}
@Override
public void setlista(String host, List<Arquivo> allfiles) throws RemoteException {
//inserre todos os elementos da lista na lista completa
for(int i=0;i<allfiles.size();i++){
arquivos.add(allfiles.get(i));
}
this.host=host;
//adiciona o host a lista de clientes
clientes.add(host);
// se lista de clientes aumentou e entao atualiza
//lista de arquivos e clientes nas telas cliente
}
@Override
public void setAplication(URL url) throws RemoteException {
urls.add(url);
}
}