Tenho certas dificuldades em compreender algumas linhas de código.
Alguém me podia interpretar este código. Gostava de conhecer outras interpretações!
public class Serv extends UnicastRemoteObject implements Servico{
Vector IndArray = new Vector();
int i = 0;
int Max = 0;
public ServicoChatImpl() throws RemoteException {
System.out.println("Objecto do servidor chat criado!") ;
}
public synchronized int conect(String nome, ClienteChat refCliente) throws RemoteException {
IndArray.add(new Cliente(nome,refCliente));
System.out.println("Cliente [" + nome + "] ligado.");
return 1;
}
public int escrita(String nome, String msg) throws RemoteException {
Cliente temp;
ClienteChat callback;
for(i=0;i<IndArray.size();i++){
temp = (Cliente)IndArray.elementAt(i);
try {
if(temp.nome.compareTo(nome)!=0) {
callback = (ClienteChat) Naming.lookup("rmi://localhost:5118/"+temp.nome);
callback.novaMensagem(IndArray.size()+":"+nome+": "+msg);
}
} catch(Exception e){System.out.println(e);};
}
System.out.println(IndArray.size()+":"+nome+": "+msg);
return 1;
}
public synchronized int logout(String nome) {
Cliente temp;
for(i=0;i<IndArray.size();i++){
temp = (Cliente)IndArray.elementAt(i);
if (temp.nome.compareTo(nome)==0) {
IndArray.remove(i);
}
}
System.out.println("Cliente [" + nome + "] saiu fora.");
return 1;
}
}
class Cliente {
String nome;
ClienteChat refCliente;
public Cliente(String nome, ClienteChat refCliente) {
this.nome = new String(nome);
}
}