-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer.java
More file actions
54 lines (42 loc) · 1.61 KB
/
Server.java
File metadata and controls
54 lines (42 loc) · 1.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
import com.google.gson.Gson;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.*;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import static java.lang.Thread.sleep;
public class Server {
public static final int PORT = 6879;
public static byte[] buffer = new byte[1000000000];
public static ConcurrentHashMap<String, Human> collection = new ConcurrentHashMap<>();
public static DatagramSocket socket;
public static void main(String[] args) {
String result = new String();
String[] splitedLine;
Gson gson = new Gson();
if (args.length != 0) {
collection = Orders.importCollection(collection, args[0]);
} else {
System.out.println("Путь до файла не был указан");
}
try {
String quote = new String();
socket = new DatagramSocket(PORT);
while(true) {
DatagramPacket request = new DatagramPacket(buffer, buffer.length);
socket.receive(request);
quote = new String(buffer, 0, request.getLength());
splitedLine = quote.split(" ", 2);
result = splitedLine[0];
System.out.println(result);
Thread RequestThread = new RequestThread(splitedLine, request);
RequestThread.start();
}
}catch(Exception o){
System.out.println(o);
}
}
}