Socket programming with JS!

B

Boomer

Hello,

Is it possible to live-capture data with JS? The XMLHttpRequest() method is
not really suitable for live data capture.

Any hints/directions?

TIA

Boomer
 
T

Tim Williams

Boomer said:
Hello,

Is it possible to live-capture data with JS? The XMLHttpRequest() method
is not really suitable for live data capture.

Any hints/directions?

TIA

Boomer

In what context ? js has no "native" file/stream functionality, so maybe
there are existing objects which you could script to achieve your aim...

Tim
 
T

Tom Cole

To be honest, HTTP itself isn't really suitable for live data capture.
The whole request, response thing, you know.....

Any reason you couldn't use XmlHttpRequest with a timer?
 
B

Boomer

"Any reason you couldn't use XmlHttpRequest with a timer?"



The data is somewhat unpredictable and in many case repetitious. There is no
way of knowing the data that is being captured is old or new when using
XMLHttpRequest().



Thanks for all your comments.



Boomer
 
V

VK

Boomer said:
The data is somewhat unpredictable and in many case repetitious. There is no
way of knowing the data that is being captured is old or new when using
XMLHttpRequest().

XMLHttpRequest is simply a "virtual browser" (with very harrow
functionality) programmatically created inside the real one. This way
old data/new data question must be solved by the regular Web browsing
means: by setting and checking cache-related headers. It can be also
HEAD request made before GET/POST to see if you need to make new data
request.
If you are thinking of a socket listener, so you would get automated
server notification on new data ready - then HTTP doesn't deal with
such things. Respectively a web-browser has nothing to offer on this
matter.
 
B

Bart Van der Donck

Boomer said:
Is it possible to live-capture data with JS? The XMLHttpRequest() method is
not really suitable for live data capture.

Though its name suggests the opposite, XMLHttpRequest() can be used to
fetch non-XML data as well. And the connection doesn't need to point
to the 'default' http daemon as well; e.g. http://12.34.56.789:585
should take you to port 585 instead of (common) 80.

But the service must accept HTTP-style socket communication anyhow if
you want to connect from a javascript client.
 
S

sam.partington

Boomer said:
The data is somewhat unpredictable and in many case repetitious. There is no
way of knowing the data that is being captured is old or new when using
XMLHttpRequest().

One solution to this is to have a sequence number that is incremented
on each request. The server keeps track of changes in status, and
remembers the current sequence number t, and sends that sequence number
with each request. When the client issues a request it sends the last
sequence number it received u, the server sends any changes in the data
between u and t.

It requires a somewhat complex state machine running on the server, but
the client side is easy enough.

Typically you would put a limit on the age of sequence numbers, if the
client sends one that is too old the server sends a 'keyframe' that
includes all data, allowing the client to reset everything to the
current status.

The system is still poll driven rather than interrupt driven, but
signifcantly reduces the traffic volume. (And it sounds like that is a
goal in your case).

HTH

Sam
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top