-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.java
More file actions
38 lines (31 loc) · 1.2 KB
/
server.java
File metadata and controls
38 lines (31 loc) · 1.2 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
import java.net.*;
import java.sql.*;
import java.io.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class server {
public static void main(String[] args) throws Exception {
String url = "jdbc:mysql://localhost:3306/DATABASE_NAME";
String uname = "USERNAME";
String pass = "PASSWORD";
Connection con = DriverManager.getConnection(url,uname,pass);
int port = 1234;
ServerSocket serverSocket = new ServerSocket(port);
ExecutorService service = Executors.newCachedThreadPool();
while(true) {
Socket s = null;
s = serverSocket.accept();
ObjectInputStream ip = new ObjectInputStream(s.getInputStream());
ObjectOutputStream op = new ObjectOutputStream(s.getOutputStream());
int privilage = (int)ip.readObject();
if(privilage == 0) {
System.out.println("Admin logged in");
service.execute(new adminHandler(s,ip,op,con));
}
else {
System.out.println("Guest logged in");
service.execute(new clientHandler(s,ip,op,con));
}
}
}
}