views:

153

answers:

2

I need a simple way to use XMLHttpRequest as a way for a web client to access applications in an embedded device. I'm getting confused trying to figure out how to make something thin and light that handles the XMLHttpRequests coming to the web server and can translate those to application calls.

The situation:

  • The web client using Ajax (ExtJS specifically) needs to send and receive asynchronously to an existing embedded application. This isn't just to have a thick client/thin server, the client needs to run background checking on the application status.
  • The application can expose a socket interface, with a known set of commands, events, and configuration values. Configuration could probably be transmitted as XML since it comes from a SQLite database.
  • In between the client and app is a lighttpd web server running something that somehow handles the translation. This something is the problem.

What I think I want:

  • Lighttpd can use FastCGI to route all XMLHttpRequest to an external process. This process will understand HTML/XML, and translate between that and the application's language. It will have custom logic to simulate pushing notifications to the client (receive XMLHttpRequest, don't respond until the next notification is available).
  • C/C++. I'd really like to avoid installing Java/PHP/Perl on an embedded device. So I'll need more low level understanding.

How do I do this?

  • Are there good C++ libraries for interpreting the CGI headers and HTML so that I don't have to do any syntax processing, I can just deal with the request/response contents?
  • Are there any good references to exactly what goes on, server side, when handling the XMLHttpRequest and CGI interfaces?
  • Is there any package that does most of this job already, or will I have to build the non-HTTP/CGI stuff from scratch?

Thanks for any help! I am really having trouble learning about the server side of these technologies.

A: 

If I understand correctly, the way I approach this problem would be a 3-tier (Don't get hang up so much on the 3-tier buzz words that we all have heard about):

  1. JavaScript (ExtJs) on browsers talks HTTP, Ajax using XmlHttpRequest, raw (naked) or wrapper doesn't really matter, to the web server (Lighttpd, Apache, ...).
  2. Since the app on the embedded device can talk by socket, the web server would use socket to talk to the embedded device.
  3. You can decide to put more business logic on the JavaScript, and keep the Apache/Lighttpd code really thin so it wont timeout.

In this way, you can leverage all technologies that you're already familiar with. Ajax between tier 1 and 2 is nothing new, and use socket between 2 and 3.

Khnle
I know what a socket is, the question is how to translate whatever HTTP is coming to the server into usable bits of information, and generate the proper HTTP response. I haven't found good resources on how to implement a backend process in C/C++, instead of installing a package like PHP.
Ian
A: 

I did not mean that you did not know socket. I just proposed a way to take a desc of a problem where I hear a lots of words: XML/HTML/Ajax/XmlHttpRequest/Java/PHP/Perl/C++/CGI and more and offer a way to simplify into smaller, better understood problem. Let me clarify:

If you want to ultimately retrieve data from the embedded devices and render on the browsers, then have the browsers making a request to the web server, the web server uses socket to talk to the embedded device. How the data is passed between browser and server, that's normal HTTP, no more, no less. Same thing between web server and embedded device, except socket instead of HTTP.

So if just you take a simple problem, like doing an addition of 2 numbers. Except these 2 input numbers would get passed to the web server, and then the web server passes to the embedded device, where the addition is carried out. The result gets passed back to the web server, back to the browser for rendering. If you can do that much, you can already make the data flow everywhere you want to.

How to parse the data depends on how you design the structure of the data that might include container which wraps around a payload.

"... whatever HTTP is coming to the server into usable bits of information, and generate the proper HTTP response"

...but that's not any different than how you handle the HTTP request on the server using your server-side language.

...how to implement a backend process in C/C++, instead of installing a package like PHP

If the embedded device is programmed in C/C++, you are required to know how to do socket programming in C/C++. On your web server, you also have to know how to socket programming, except that will be in that server-side language.

Hope this helps.

Khnle