-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer.java
More file actions
46 lines (35 loc) · 1.36 KB
/
Server.java
File metadata and controls
46 lines (35 loc) · 1.36 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
package com.example;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.security.KeyPair;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.util.logging.Logger;
import com.example.config.AppConfig;
import com.example.utils.Cryptography;
public class Server {
private static final Logger LOGGER = Logger.getLogger(Server.class.getName());
public static void main(String args[]) throws NoSuchAlgorithmException, IOException {
ServerSocket serverSocket = null;
try {
serverSocket = new ServerSocket(AppConfig.SERVER_PORT);
LOGGER.info("Server started and listening on port "+ AppConfig.SERVER_PORT);
while (true) {
Socket clientSocket = serverSocket.accept();
KeyPair keyPair = Cryptography.buildKeyPair();
PublicKey publicKey = keyPair.getPublic();
PrivateKey privateKey = keyPair.getPrivate();
ClientServerConnection connection = new ClientServerConnection(clientSocket, publicKey, privateKey);
connection.start();
}
}
catch (IOException e) {
LOGGER.warning("Error: "+ e.getMessage());
}
finally {
serverSocket.close();
}
}
}