Implement Ajax calls via XMPP messages - ajax

I have a website where users are connected with XMPP server (ejabberd). I want to replace my ajax calls with xmpp messages to reduce the load on apache server.
ie
a replace for ajax call, which works on following ideas
Send a XMPP message
Add a handler which is fired when the data for the specific ajax request is answered through a message
Is there a wrapper to do the same?

You could take a look at strophe.js.
It's a pretty powerful JavaScript library for doing XMPP in the browser.

Related

ColdFusion API and Websockets

I am hoping someone can point me in the right direction. I have a CF2021 Server which uses a Node.js websocket server and CF pages (via javascript) as a client. Messages from user to user work as expected, so no issue there.
This CF Server also has a custom API built using CFML that handles and routes inbound SMS messages. My question is; what would be the best way to send the SMS message (by now its json) to the Node.js websocket to it can send it to the user(s).
I tried using the same javascript that the browser client uses, but it appears that the CFML API script is "browser-less", so that doesn't work, or should it?
I thought something like Apache Groovy may be the solution, but I am having difficulties with any websocket example I have found.
Any suggestions would be greatly appreciated.
thanks in advance
Flow matters.
If you want to handle an incoming message by delivering it to all currently logged in users who are subscribed to messages of the current sort: set up your message handler to deliver using lucee/adobe-coldfusion websockets. Be forewarned, Lucee takes some setup time, but once running, it is a great solution.
If you don't need immediate delivery, or you need a super simple solution: I actually have had some success with "Long Polling" you just have to remember to use "flush" early in the request, before any pause/sleep, then loop your message lookup requests for new data, with a 1-5 second delay between each loop. Once new data is found, I like to return the request to the client, close that polling request and start a new polling request using the client side. I typically won't poll for more than 60 seconds. Even if the returned json object is empty.

How to subscribe websocket by Chrome extensions?

I am try to implement a basic web socket app by following this tutorial:https://spring.io/guides/gs/messaging-stomp-websocket/
However, in that tutorial there was a client UI implementation. I don't want to use UI. Instead of the UI, I want to use a websocket client extension in Chrome for sending and seeing messages.
All codes same with the tutorial(except the UI part since I'dont want UI), so I don't rewrite all codes here.
I am able to connect and send message to the url: ws://localhost:8081/gs-guide-websocket for example,
However, I can't get response with this url: ws://localhost:8081/topic/greetings. (I use this URL for getting responses by subscribing it. Because this topic/greetings path used in the UI side of that tutorial for subscription)
The Chrome extension that I used is Simple WebSocket Client.
Why I couldn't subscribe the ws://localhost:8081/topic/greetings url? and How can I get messages from the server by using the Chrome client websocket extensions?
Your application works with STOMP and SockJs, this plugin does not support that. It only works with ws. In this example, you can write a simple ws endpoint for your application:
example simple ws endpoint

Grails: server-to-client notification

I'm building a Grails app which queries several API's across the Web. The problem is that this queries are very time consuming and it is really annoying for the user to click one button and wait so much time without nothing changes in the page.
The basic architecture of my app is, when the user clicks the button, the client side performs an Ajax request with Prototype library to the server side. The server side, then, connects to the Last.fm API and retrieve a list of events. When the server side is finished populating the list with events it sends a JSON response to the client side which allows the client side to create markers for each event on a Google map.
What I want to achieve is, instead of waiting for all the events being retrieved from the API to send the JSON response, the server side sends a JSON response as soon as it retrieve one event, allowing the client side to populate the map while other events are yet being retrieved.
Any ideas how can I implement this? I read about the concept of Ajax Push but I'm not sure if it is what I need.
Thanks for the help!
There is no way to open a listening connection on the client that your server might connect to. Instead, what you need is a connection to the server that is kept alive and can be used to receive events. This way, you could directly return the "action" request and inform the client through your persistent event connection once the last.fm request was completed.
That said, the way I would implement is using ajax keep alive.
Take a look at cometd plugin.

Realitme via ajax, How to create an open connection to a non-blocking server like tornado etc?

When people create real-time web apps, they are leaving a ajax request open/long running.
how do they do this in javascript?
There is really no difference from a normal ajax request. A callback is associated with the XMLHttpRequest. Once the request is complete the callback is invoked. The difference is on the server-side where the request is held open until data is ready for the client, or a timeout occurs. On the browser side, the callback is invoked as each successive request is answered. The callback must process the data from the server and initiate another request. The request is handled asynchronously, so the browser is not blocked.
A really good example of the whole thing is the chat demo included in Tornado.

How to use websocket to strengthen ajax?

HTML5 will be next super star.
So~~~How to using new idea to implement AJAX on the WebSocket in HTML5 spec?
thx....
I think you misunderstand ajax and websockets.
All internet programs operate by using a special kind of connection known as a socket (sockets can also be used for other things, but thats not important right now). For example, when you access a webpage in Chrome, Chrome creates a socket and uses that to connect to the webserver (there are other steps, but thats the simple explanation).
Ajax is a method for updating content on a page without reloading that page (or going to a new page), this is useful for dynamic content. Ajax works through the XMLHttpRequest object in the DOM Api. When you make an Ajax request, you're asking the web browser to initiate a new connection on your behalf (the web browser may then create a new socket as it sees fit).
Websockets is an alternative api which allows you more control over the socket the web browser creates. In essence its an alternative technology which accomplishes a similar purpose. Ajax sends only a single HTTP request (usually post or get), and receives the appropriate response, thus the advantage of websockets are 2 fold:
Websockets allows for non HTTP transfers (for example, streaming VoIP).
Websockets allow for bi-direction transfers, (ie. servers making follow up requests to client).
This is not to say Ajax isn't still useful, but that Websockets allow you to do things you can't with Ajax.

Resources