Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » OM2M » monitor on python or monitor.jar source code or explanation
monitor on python or monitor.jar source code or explanation [message #1786293] Mon, 30 April 2018 02:43 Go to next message
Jairo  Ariza is currently offline Jairo ArizaFriend
Messages: 9
Registered: March 2018
Junior Member
Hello , I have run the subscription to a data container as explained in https://wiki.eclipse.org/OM2M/one/REST_API. Now I want to implement a subscription to a python web app. Anyone can help me to do develop this? Or an explanation or the monitor.jar source code.

Thanks for your help.
Re: monitor on python or monitor.jar source code or explanation [message #1786807 is a reply to message #1786293] Sat, 12 May 2018 15:04 Go to previous message
Jairo  Ariza is currently offline Jairo ArizaFriend
Messages: 9
Registered: March 2018
Junior Member
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);
}
}
}
Previous Topic:Connection between multiple servers or gateways.
Next Topic:CoAP between App and in-cse
Goto Forum:
  


Current Time: Thu Oct 10 17:27:03 GMT 2024

Powered by FUDForum. Page generated in 0.03240 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top