AJAX with embedded server questions

D

Dave Boland

I'm planning a software upgrade to an embedded device that uses a PC
web browser as the GUI for configuration and data report. The new
requirements need faster refreshing so it seems real time, and only
key data is being updated. Sounds like a possible application for
AJAX, but I have a few questions before I go down that road. My hope
is that some of you have also done something like this.

First some more information about the application. The embedded
processor has a RTOS, web server, limited RAM and flash, 500 KB/s
network port. The server scripts are written in C. The data being
refreshed dynamically (without tags) is about 60 bytes per line, 32
lines, for a total of just under 2KB every second. Tags may increase
the data load to 5 KB every second. The data is tabular, but my
suspicion is that sooner or later there will be a graphical display.

Questions:
1. Is JavaScript/AJAX the best way to do this, or would a Java app.
offer better performance? I have yet to find a good comparison
between the two doing essentially the same task.

2. How do I write code that can manage multiple requests for
different data that will return out of order? All of the AJAX code
examples I have seen so far seem to assume the request is filled (or
error) before another request is sent. In this situation I may want
to break up the application into a number of smaller requests to
reduce the data per request.

3. AJAX libraries. I was looking at two libraries this morning
(prototype and ZK), but it is not clear to me what the benefit would
be for a simple application like this one. Are there other libraries
that I should look at?

4. Is JASON the better way to move data from the server to the
application? From what I have learned it seems that there would be
less data across the network (compared to XML) and the JavaScript
overhead to write the data looks to be better. Still, the tags
increase the data transported by at least 2X, so I'm also considering
a custom format like we do if the data was going across a really slow
serial connection (9600 bps).

5. Any other topic I should address that I currently have no
awareness (at this time)?

Thanks for the help.

Dave,
 
S

Steve Swift

Dave said:
2. How do I write code that can manage multiple requests for different
data that will return out of order?

I'm a rank amateur at this (got my first Ajax interaction working about
2 weeks ago) but the asynchronous call and subsequent call completion
don't seem to have any dependencies/conflicts with other
calls/completions going on. Of course, most browsers run JavaScript
single-threaded, so you would end up submitting the xmlhttp requests
synchronously. However, you could submit request A, then request B, and
have completion B happen before completion A. This might be affected by
interlocks if A and B interfered with each other on the server (suppose
A acquires a lock required by B)
3. AJAX libraries. I was looking at two libraries this morning
(prototype and ZK), but it is not clear to me what the benefit would be
for a simple application like this one. Are there other libraries that
I should look at?

As I see it, these libraries help you mostly by papering over the
differences between browsers and giving you one, simple interface to the
underlying server requests. Since you are in a very closely defined
environment (you probably have no choice over either "browser" or
server) you probably don't need prototype or ZK. A colleague of mine
sent me a simple "ajax" function that works for all browsers that are
"legal" within our corporate environment (and others that are not) so I
don't really need any script libraries to help me.

The advantages of *not* using such libraries are:
1. What you don't use cannot go wrong
2. What you don't use cannot slow you down
3. It doesn't matter whether you understand it or not
4. You have only your own code to worry about

The advantages of using such libraries are:
1. They may continue to work if your environment changes (unlikely in
your specific environment with highly specialised browser/server)
2. They may be easier to learn than the raw JavaScript (which is why
I used my colleague's function)
 
T

Thomas 'PointedEars' Lahn

Dave said:
I'm planning a software upgrade to an embedded device that uses a PC web
browser as the GUI for configuration and data report. The new
requirements need faster refreshing so it seems real time, and only key
data is being updated. Sounds like a possible application for AJAX, but
I have a few questions before I go down that road. My hope is that some
of you have also done something like this.

I am developing Web applications that use XHR, but not on an embedded device
so far.
First some more information about the application. The embedded
processor has a RTOS, web server, limited RAM and flash, 500 KB/s network ^^^^^^^^^^^^^^^^
port. The server scripts are written in C. The data being refreshed
^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^
dynamically (without tags) is about 60 bytes per line, 32 lines, for a ^^^^^^^^^^^
total of just under 2KB every second.

That would hardly matter as (IIUC) client and server are on the same device.
Are they?
[...]
Questions: 1. Is JavaScript/AJAX the best way to do this, or would a
Java app. offer better performance? I have yet to find a good comparison
between the two doing essentially the same task.

I presume that a Java applet or application would require more memory to do
the same and might (therefore) be slower than an ECMAScript application and
less suitable for your application. But this is a question for a more
general newsgroup.
2. How do I write code that can manage multiple requests for different
data that will return out of order? All of the AJAX code examples I have
seen so far seem to assume the request is filled (or error) before
another request is sent. In this situation I may want to break up the
application into a number of smaller requests to reduce the data per
request.

You can use several different XHR objects to handle concurrent requests.
However, HTTP clients usually limit the number of active connections to the
same host, so you may have to deal with that bottleneck as well.
3. AJAX libraries. I was looking at two libraries this morning
(prototype and ZK), but it is not clear to me what the benefit would be
for a simple application like this one.

The benefit of a library is what you expect from a library as compared
to a simple script. So you should ask yourself why you were looking for
libraries in the first place, and then compare your expectations with what
you got; then you have your answer.
Are there other libraries that I should look at?
Yes.

4. Is JASON the better way to move data from the server to the
application?

Whether *JSON* is more suitable than other formats depends on the type of
data that you want to transmit.
From what I have learned it seems that there would be less data across
the network (compared to XML) and the JavaScript overhead to write the
data looks to be better.

ISTM that JSON tends to require less overhead for less structured
information, and is easier to parse, which I suppose is why it was devised.
See e.g. the Google Groups archives of this newsgroup for a lengthy
discussion on the topic of XML vs. JSON.
Still, the tags increase the data transported by at least 2X, so I'm also
considering a custom format like we do if the data was going across a
really slow serial connection (9600 bps).

However, a custom format would require custom parsing, which would be
slower. XML does not, for there are built-in XML parsers that can be used;
JSON also does not, unless you do not want to use eval().
5. Any other topic I should address that I currently have no awareness
(at this time)?

Probably.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top