Hi,
I have the following situation.
A driver acting as server via smart-serial.
If a request is made via postman or curl.
A response with 200 and the json body will be visible on the stream viewer.
On postman a status 200 will be available but it will keep waiting until timeout or until the driver is stopped.
Similar with curl.
Tried to close the connection with a close action but i may be missing something.
Could you please give me some advice in how to implement this feature?
Thanks in advance.
If it's unnecessary to implement a full-fledged HTTP Web server, a minimal response for a request should be like this:
HTTP/1.1 200 OK
Content-Length: 13
Content-Type: text/plain; charset=utf-8
My answer
The Content-Length should be the body's length, and there must be a new line between the headers and the body. Notice this solution is not intended to be a robust server communication channel but more for occasional confirmation and lightweight responses.
Julio, do I understand it correctly that you're trying to implement an HTTP-server in a smart-serial driver? That seems quite ambitious, and basically means you'll have to dig deep in the RFC of HTTP to see how connection management is done.
If your element needs to act as the server to handle http requests, then I don't think there is any other way than implementing a custom web service in a QAction. I assume you will only have one of these elements running on your DMS?
Implementing a custom web service in a QAction will have some limitations as communication will "bypass" DataMiner so you won't see this in the stream viewer for example. You'll also need to make sure you are closing the service whenever your element is stopped or deleted.
Thank you very much for the feedback.
Thank you @Gelber Mahecha fixing the HTTP structure worked great!!