|
Re: monitor on python or monitor.jar source code or explanation [message #1786807 is a reply to message #1786293] |
Sat, 12 May 2018 11:04  |
Eclipse User |
|
|
|
Hello.
I have decoded the monitor.jar file. I have little practice in java, so if anyone can help me with an explanation of the code, it will be appreciated.
I have one question, the subscription is implemented with web sockets?
Here is the code and thanks for your help.
package httpapplication;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.net.InetSocketAddress;
public class Monitor
{
private static int port = 1400;
private static String context = "/monitor";
public Monitor() {}
public static void main(String[] args) throws Exception { System.out.println("Starting server..");
HttpServer server = HttpServer.create(new InetSocketAddress(port), 0);
server.createContext(context, new MyHandler());
server.start();
System.out.println("The server is now listening on\nPort: " + port + "\nContext: " + context + "\n");
}
static class MyHandler implements HttpHandler {
MyHandler() {}
public void handle(HttpExchange t) throws IOException { String body = "";
try
{
InputStream is = t.getRequestBody();
int i;
while ((i = is.read()) != -1) { int i;
char c = (char)i;
body = body + c;
}
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Received notification:");
System.out.println(body);
t.sendResponseHeaders(204, -1L);
}
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.03351 seconds