-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.java
More file actions
108 lines (87 loc) · 3.61 KB
/
Client.java
File metadata and controls
108 lines (87 loc) · 3.61 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
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
104
105
106
107
108
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.Scanner;
// To change the 2 input parameters (double numbers) in Intellij go to: Edit Configurations -> Client -> Built and Run
public class Client {
public static void main(String args[]) {
try {
String ip;
int port;
int fn;
Scanner ss1 = new Scanner(System.in);
ip = ss1.nextLine();
Scanner ss2 = new Scanner(System.in);
port = ss2.nextInt();
Scanner ss3 = new Scanner(System.in);
fn = ss3.nextInt();
// connect to the RMI registry
Registry rmiRegistry = LocateRegistry.getRegistry(port);
System.out.println("Connected to message server with ip: "+ip+" and port: "+port);
// get reference for remote object
MessageC stub = (MessageC) rmiRegistry.lookup("messanger");
//end of server connect stuff
switch (fn) {
case 1: {
System.out.println("fn=1 selected");
String username;
Scanner fn1 = new Scanner(System.in);
username = fn1.nextLine();
System.out.println(stub.CrateAccount(username));
}
case 2:{
int auth;
Scanner fn2 = new Scanner(System.in);
auth = fn2.nextInt();
System.out.println(stub.ShowAccounts(auth));
}
case 3:{
String reciver;
int auth;
Scanner fn3 = new Scanner(System.in);
auth = fn3.nextInt();
Scanner fn4 = new Scanner(System.in);
reciver = fn4.nextLine();
String message;
Scanner fn5 = new Scanner(System.in);
message = fn5.nextLine();
System.out.println(stub.SendMessage(auth,reciver,message));
}
case 4:{
int auth;
Scanner fn6 = new Scanner(System.in);
auth = fn6.nextInt();
System.out.println(stub.ShowInbox(auth));
}
case 5:{
int idm;
int auth;
Scanner fn7 = new Scanner(System.in);
auth = fn7.nextInt();
Scanner fn8 = new Scanner(System.in);
idm = fn8.nextInt();
System.out.println(stub.ReadMessage(auth,idm));
}
case 6:{
int idm;
int auth;
Scanner fn9 = new Scanner(System.in);
auth = fn9.nextInt();
Scanner fn10 = new Scanner(System.in);
idm = fn10.nextInt();
System.out.println(stub.DeleteMessage(auth,idm));
}
default:{
System.out.println("Unavailable FN_ID Choice");
}
System.out.println("changes saved closing");
break;
}
//System.out.println("Addition result : " + stub.add(a, b));
System.out.println(ip +"\n" +port);
//end of client program
} catch (Exception e) {
//in case the server doesnt work
System.out.println(e);
}
}
}