Question

I've always wanted a way to make a socket connection to a server and allow the server to manipulate the page DOM. For example, this could be used in a stock quotes page, so the server can push new quotes as they become available.

I know this is a classic limitation (feature?) of HTTP's request/response protocol, but I think this could be implemented as a Firefox plugin (cross-browser compatibility is not important for my application). Java/Flash solutions are not acceptable, because (as far as i know) they live in a box and can't interact with the DOM.

Can anyone confirm whether this is within the ability of a Firefox plugin? Has someone already created this or something similar?

Was it helpful?

Solution

You may want to look at Comet which is a fancy name for a long running HTTP connection where the server can push updates to the page.

OTHER TIPS

It should be possible. I have developed a xulrunner application that connects to a TCP server using sockets. Extension development would likely have the same capabilities. I used a library from mozdev - JSLib. Specifically check out the networking code. The fact that there is a Firefox add-on for JSlib add-on for Firefox makes more more confident.

Essentially, as I understand it, sockets are not part of JavaScript, but through XPCOM, you can get raw socket access like you would in any c/c++ application.

Warning: JSLib doesn't seem to receive a lot of attention and the mailing list is pretty sparse.

Java/Flash solutions are not acceptable, because (as far as i know) they live in a box and can't interact with the DOM.

That's not actually true of Java. You can interact with Java via JavaScript and make DOM changes.

http://stephengware.com/proj/javasocketbridge/

In this example there are two JavaScript methods for interaction

Send:

socket_send("This was sent via the socket\n\n");

Receive:

on_socket_get(message){ more_code(message); }

You may want to look at Comet

a.k.a. server push. This does not let the server "update" the client page directly, but all the new data is sent to the page through a single connection.

Of course, a Firefox extension (as well as plugins, which are binary libraries that can do whatever any other application can do) can work with sockets too. See 1, 2.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top