Need help with Reverse AJAX/Comet/Long-Polling

Hi,
To summarize: How do I post data to xml file on server AND update page with changes to xml file (maybe JSON) asynchronously?

I’m a graphic designer and I’m familiar with HTML/CSS however I need help with Javascript, i’ve only played around with jQuery. I’m working on a browser-based call screener for radio talk shows. The client will have Call, Drop, and several other functions along with indicators for when something changes on the server/talk show system. These buttons should post data to a web server that is connected to a phone bridge/digital hybrid that’s programmed with C code to control the talk show system. Yes, I know, this is way over my head. I’ve done a similar project that used AJAX and an iFrame that would poll the server every second. That was basically just a remote control. For a 6-12 line talk show screener, we need something more efficient. I’ve tried looking for samples similar to this and couldn’t find anything so I need someone to help walk me through this. I know that web sockets would be most efficient but the developer writing the C-code says that the server he’s working on wouldn’t support it. It’s a Coldfire processor and Netburner software. Does anyone know if this server would be able to support web sockets? Otherwise, I’m left to long-polling. I was hoping I could just post data to an xml or php file on the server and check that same file for changes made from the C code and update the client page with css class changes and javascript that would change text, button states and colors.

To start simple, I just want to send 3 commands (Call, Drop, Hold) and to find out from the server if the line is in use, ringing, or on hold based on a class change and update the client page asynchronously. Eventually it will have to be specific to a phone line and will retrieve calling line ID information. I would like the call/drop buttons to submit via javascript instead of a form so that it doesn’t refresh the page at each button push. The server will have several instances of the browser so that people from screen calls from different computers and will have browser-to-browser chat. Therefore people will have to log in. Again, web sockets would be ideal if it’s possible. Ideally we hope this will be compatible with all browsers including mobile.

Can anyone walk me though this or point me to someone or an example that would help?

Hi, welcome to the forums!

That sounds like a really interesting and ambitious project you have there! I’d never heard of a Netburner server before, so I did a bit of googling and it appears to be some kind of module for interfacing electronic equipment with computers?

I managed to find a websockets library written in C, which might be of interest to your dev guy. One potential issue may be that the hardware is not up to the task of handling multiple websocket connections, but not knowing anything about the device I couldn’t say.

If that’s a no-go, another possible solution would be to set up a server to act as a middle-man - it would have to receive messages from the Netburner module, maintain websocket connections to all the clients, and relay any commands received from the clients back to the phone system.

Indeed it does :slight_smile:

If the websockets option doesn’t pan out, here’s a reasonably good explanation of how you might go about implementing long polling.

Let us know how you get on.

That’s pretty much what I want to do. The question is how do I do it? If someone could just write up a functioning example of a button, that would be amazing.

Just something small, say, I have a call button and an indicator for the line status, and all I need is a HTML file for the client and an XML file for the server. The button should be able to update a message to the xml file on the server, and if I manually change a CSS class name on the XML file, the HTML page should update that class change as soon as I save the XML file. When I say it like that, it sounds easy, but I’m only good with javascript if I’m working with existing code. When it comes down to the order of writing new code, I’m lost.

If anyone can write that up for me, I could do the rest from there.

I came across that website in my search, however it only shows one function of the code. I don’t know where to go from there. That article only has a link to the comet wikipedia article and doesn’t have a working example. I’m also guessing that site is for people buying the javascript dashboard gauges. I’m sure that function would work if I knew how to implement the rest of the code.

Hi,

I noticed you mentioned using an XML file, and I see now that you’d mentioned it in your initial post, but how does XML fit into all of this?

The XML file would be the database to store all the data between (middle-man). Eventually I would like the users to be able to chat browser to browser. If there’s a better format, please let me know. Perhaps JSON? I’d have to figure that out.

Writing to and from an XML file is probably not ideal… files are the slowest way to read/write data. Any data wants to be passed immediately through from phone system to the client machines or vice-versa.

The kind of thing I was thinking was using a Node.js server as the middle-man - once you start the program, it stays running in memory (unlike PHP, which only runs for the duration of the request) and is well suited to a real-time application such as this. I do realise though that this probably isn’t a very practical suggestion if you don’t have much experience with Javascript.

A lot depends on how much flexibility you have with the Netburner part of the equation. Is the software already written, and you’ve a fixed system to work with? Or is your C developer willing to work with you to come up with something that meets your requirements?

Sorry, I was sidetracked with other projects. I’m working with a fixed system thats already written. I suppose the C developer would have to work to come up with something else that would support Node if we can’t get it to work.