-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer.java
More file actions
executable file
·64 lines (58 loc) · 1.8 KB
/
Server.java
File metadata and controls
executable file
·64 lines (58 loc) · 1.8 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
import com.google.gson.Gson;
import com.sun.security.ntlm.Client;
import java.io.InputStream;
import java.net.*;
import java.lang.*;
import java.nio.charset.Charset;
import java.util.*;
import java.util.logging.*;
public class Server {
static ServerSocket server;
static Socket connection;
static Logger log = Logger.getLogger(Server.class.getName());
static boolean ServerStart(int port){
try {
server = new ServerSocket(port);
}
catch (Exception e){
log.log(Level.INFO, "server failed to start");
return false;
}
try {
log.log(Level.INFO, "Waiting for connection");
connection = server.accept();
}
catch (Exception e){
return false;
}
log.log(Level.INFO, "Connection from " + connection.toString());
return true;
}
static String SendJson(){
String jsonClient = JsonWork.GenJsonClientData();
try {
connection.getOutputStream().write(jsonClient.getBytes());
}
catch (Exception e) {
}
return jsonClient;
}
public static void main(String[] args) {
ServerStart(8005);
for(int i = 0; i < 100000; i++) {
String json = SendJson();
log.log(Level.INFO, "Sent json number " + i + " " + json.substring(0,json.indexOf("}")) + " ...");
try {
while (connection.getInputStream().read() != 1) ;
}
catch (Exception e){
log.log(Level.INFO, "Error occured during waiting");
return;
}
}
try {
connection.getOutputStream().write(0);
}
catch (Exception e){}
}
}