-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer.java
More file actions
65 lines (57 loc) · 1.52 KB
/
Server.java
File metadata and controls
65 lines (57 loc) · 1.52 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
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import Database.Database;
public class Server
{
private Socket socket;
private Database database = new Database();
public Server()
{
database.load();
}
public void run()
{
try (ServerSocket serverSocket = new ServerSocket(2004, 10))
{
try
{
while (true)
{
System.out.println("Waiting for new connection");
socket = serverSocket.accept();
System.out.println("Connection received from " + socket.getInetAddress() + ":" + socket.getPort());
ServerLogic logic = new ServerLogic(socket, database);
logic.start();
}
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
// Closing connection
try
{
serverSocket.close();
socket.close();
}
catch (IOException ioException)
{
ioException.printStackTrace();
}
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
public static void main(String args[])
{
System.out.println("\n\n-- Server --\n\n");
Server server = new Server();
server.run();
}
}