-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCliente3.java
More file actions
56 lines (45 loc) · 2.15 KB
/
Copy pathCliente3.java
File metadata and controls
56 lines (45 loc) · 2.15 KB
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
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.Scanner;
import java.io.FileReader;
import java.util.Random;
public class Cliente3 {
private Cliente3() {}
public static void main(String[] args) {
int idClient = Integer.parseInt(args[0]); // Definição do id do cliente
System.out.println("------------- Cliente3 " + idClient + " -----------\n\n");
Scanner startEvent = new Scanner(System.in);
try {
Registry registry = LocateRegistry.getRegistry(0);
ClienteServidor stub = (ClienteServidor) registry.lookup("ClienteServidor");
Thread.sleep(1000);
leitura(stub, idClient);
escrita(stub, idClient);
System.out.println("---------\n");
System.out.println("Tudo finalizado! digite qualquer coisa para sair");
startEvent.nextLine();
}catch (NotBoundException | RemoteException | InterruptedException e ) {
System.err.println("Capturando a exceção no Cliente: " + e.toString());
startEvent.nextLine();
}
startEvent.close();
}
public static void leitura(ClienteServidor stub, int idClient) throws RemoteException, InterruptedException {
int arqNum = 1;
String arqnome = "arquivo" + arqNum + ".txt"; //
System.out.println("Fazendo LEITURA em: "+ arqnome +"\n");
String text = stub.readFile(arqNum, idClient);
System.out.println("Texto lido: " + text);
}
public static void escrita(ClienteServidor stub, int idClient) throws RemoteException, InterruptedException {
int arqNum = 1;
String arqnome = "arquivo" + arqNum + ".txt"; //
System.out.println("Fazendo ESCRITA em: " + arqnome + "\n");
String conteudo = "Cliente " + idClient + " escreveu aqui.";
//String conteudo = "Cliente escreveu aqui na vez " + Integer.toString(cont);
if(stub.writeFile(arqNum, idClient, conteudo))
System.out.println("Escrita com sucesso");
}
}