-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrintServiceClient.java
More file actions
35 lines (31 loc) · 1.18 KB
/
PrintServiceClient.java
File metadata and controls
35 lines (31 loc) · 1.18 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
import java.net.*;
import java.rmi.*;
import java.util.*;
/*
* Qui si da vita al processo client.
*/
public class PrintServiceClient {
public static void main(String[] args) {
try {
Scanner sc = new Scanner(System.in);
String s = null;
// Il client recupera il riferimento globale (un oggetto che istanzia la classe proxy in RMI) all'oggetto printservicefactory (riferimento alla factory)
PrintServiceFactory psf = (PrintServiceFactory)Naming.lookup("rmi://127.0.0.1/printservicefactory");
// Invoca il metodo remoto per la creazione dell'oggetto remoto di tipo PrintService (creiamo dinamicamente l'oggetto remoto)
// Si recupera il riferimento globale usando e invocandone il metodo print
PrintService ps = psf.create();
do {
System.out.println("Inserisci un messaggio");
s = sc.nextLine();
ps.print(s);
} while(!s.equals("."));
ps.print("Exit");
} catch (RemoteException e) {
System.err.println("Remote invocation error " + e);
} catch (MalformedURLException e) {
System.err.println("Wrong URL for binding");
} catch (NotBoundException e) {
System.err.println("Object alreay bound to the registry");
}
}
}