1 |
/* |
2 |
* i-scream central monitoring system |
3 |
* Copyright (C) 2000-2002 i-scream |
4 |
* |
5 |
* This program is free software; you can redistribute it and/or |
6 |
* modify it under the terms of the GNU General Public License |
7 |
* as published by the Free Software Foundation; either version 2 |
8 |
* of the License, or (at your option) any later version. |
9 |
* |
10 |
* This program is distributed in the hope that it will be useful, |
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
* GNU General Public License for more details. |
14 |
* |
15 |
* You should have received a copy of the GNU General Public License |
16 |
* along with this program; if not, write to the Free Software |
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 |
*/ |
19 |
|
20 |
// used for testing the java CLI client |
21 |
|
22 |
import java.net.*; |
23 |
import java.io.*; |
24 |
|
25 |
public class FakeServer { |
26 |
|
27 |
public static void main(String[] args) throws InterruptedException { |
28 |
|
29 |
final int serverPort = 2345; |
30 |
boolean running = true; |
31 |
|
32 |
while(running) { |
33 |
OutputStreamWriter writer = null; |
34 |
try { |
35 |
ServerSocket listen = new ServerSocket(serverPort); |
36 |
Socket conn = listen.accept(); |
37 |
OutputStream outStream = conn.getOutputStream(); |
38 |
writer = new OutputStreamWriter(outStream); |
39 |
System.out.println(">>> Server restarted."); |
40 |
} |
41 |
catch (Exception e) { |
42 |
// Hide and scream. |
43 |
} |
44 |
|
45 |
try { |
46 |
while(running) { |
47 |
Thread.sleep(500); |
48 |
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"; |
49 |
writer.write(packet); |
50 |
writer.flush(); |
51 |
System.out.println("Packet sent."); |
52 |
} |
53 |
} |
54 |
catch (Exception e) { |
55 |
System.out.println("arg"); |
56 |
} |
57 |
|
58 |
|
59 |
} |
60 |
|
61 |
|
62 |
} |
63 |
|
64 |
} |