Repository navigation
Expand file tree
/
Copy pathChatApplication.java
More file actions
59 lines (51 loc) · 1.66 KB
/
Copy pathChatApplication.java
File metadata and controls
59 lines (51 loc) · 1.66 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
import AuthUser.AuthUser;
import java.io.*;
import java.util.Scanner;
public class ChatApplication {
private Scanner scanner;
private AuthUser authUser = new AuthUser();
private ChatSession session = new ChatSession();
public ChatApplication() {
scanner = new Scanner(System.in);
}
// Register a new user
public boolean register(String username, String password, BufferedReader console, PrintWriter out, BufferedReader in){
try{
if(authUser.handleRegister(username , password ,console,out,in)){
return true;
}
else{
return false;
}
}
catch(IOException e){
e.printStackTrace();
return false;
}
}
// Existing authentication logic
public boolean authenticate(String username, String password, BufferedReader console, PrintWriter out, BufferedReader in){
try{
if(session.login(username, password, authUser, console, out, in)){
return true;
}
else{
return false;
}
}
catch(IOException e){
e.printStackTrace();
return false;
}
}
static {
System.loadLibrary("ChatServerConnector");
System.loadLibrary("ChatClient");
}
public native void startServer(int port); // Start the server
public native void connectToServer(String username, String serverAddress, int port); // Connect to the server
public static void main(String[] args) {
ChatApplication app = new ChatApplication();
app.startServer(12223);
}
}