-
Notifications
You must be signed in to change notification settings - Fork 1
/
Server.java
46 lines (39 loc) · 1.32 KB
/
Server.java
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.yurii.salimov.lesson11.task03;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
/**
* @author Yuriy Salimov (yuriy.alex.salimov@gmail.com)
* @version 1.0
*/
public final class Server extends Thread {
private static Integer numberRequest;
private final int port;
public Server(final int port) {
numberRequest = 0;
this.port = port;
}
@Override
public void run() {
while (!isInterrupted()) {
try (ServerSocket server = new ServerSocket(this.port);
Socket socket = server.accept();
OutputStream output = socket.getOutputStream()) {
output.write(getInfo().getBytes());
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
private String getInfo() {
return "OS: " + System.getenv("OS") +
"\n\nProcessor: " +
"\n identifier - " + System.getenv("PROCESSOR_IDENTIFIER") +
"\n architecture - " + System.getenv("PROCESSOR_ARCHITECTURE") +
"\n cores - " + Runtime.getRuntime().availableProcessors() +
"\n\nRequest number: " + getNumberAndIncrement();
}
private synchronized int getNumberAndIncrement() {
return numberRequest++;
}
}