1 |
// used for testing the java CLI client |
2 |
|
3 |
import java.net.*; |
4 |
import java.io.*; |
5 |
|
6 |
public class FakeServer { |
7 |
|
8 |
public static void main(String[] args) throws InterruptedException { |
9 |
|
10 |
final int serverPort = 2345; |
11 |
boolean running = true; |
12 |
|
13 |
while(running) { |
14 |
OutputStreamWriter writer = null; |
15 |
try { |
16 |
ServerSocket listen = new ServerSocket(serverPort); |
17 |
Socket conn = listen.accept(); |
18 |
OutputStream outStream = conn.getOutputStream(); |
19 |
writer = new OutputStreamWriter(outStream); |
20 |
System.out.println(">>> Server restarted."); |
21 |
} |
22 |
catch (Exception e) { |
23 |
// Hide and scream. |
24 |
} |
25 |
|
26 |
try { |
27 |
while(running) { |
28 |
Thread.sleep(500); |
29 |
String packet = "<packet machine_name=\"raptor\" ip=\"123.123.123.123\"><load><load1>"+Math.random()+"</load1><load5>"+Math.random()+"</load5><load15>"+Math.random()+"</load15></load></packet>\n"; |
30 |
writer.write(packet); |
31 |
writer.flush(); |
32 |
System.out.println("Packet sent."); |
33 |
} |
34 |
} |
35 |
catch (Exception e) { |
36 |
System.out.println("arg"); |
37 |
} |
38 |
|
39 |
|
40 |
} |
41 |
|
42 |
|
43 |
} |
44 |
|
45 |
} |