On twitter when someone we follow tweet something, its shown our timeline instantly. Twitter i followed the request and response with firebug there is no preiodical timer to sent a request than receive response (in this case tweets) its look like instantly receiving the new tweets. What is the methodology to do that. And what is the name of that. Can you give me some book or internet sites advices to read?
Summary: How can show the new data as soon as it arrived and how to implement that?Language does not matter.
Open an HTTP request with AJAX, but keep the connection with the server open, such that the server can continually send updated data to the browser without the overhead time and data transfer of closing and opening a new connection.
Related
Basically I have a script on a server that runs on a MQTT/CURL signal. Once either the MQTT or CURL gets called It starts/runs the script on the server and from there transfer the data to other machines. Why I want this to be run from Chrome (or any other browser) is because I would like to use a QR scanner to scan a QR code which holds the URL(mqtt or curl) and that this then gets run from the internal browser on the device. I know that there are apps and extensions for this, but I really need to get it as "thin client" as possible due to the large amount of devices that needs to be able to send the signal. Downloading an app for each device would defeat the purpose.
So my question really is if this is possible? Can Chrome send mqtt/curl from the url/address bar. I can't seem to find any information on this (maybe because it doesn't work? :D) HTTP post wont do unfortunately.
EDIT: If it doesn't work I have an idea to curl post from the console, but then my question is how would an url that opens console and inserts certain information look like? In other words I want an URL to include in my QR picture that opens Chrome (because it's a link) opens console and writes data like 101011101 (I can do the ENTER manually)
Kind regards,
First, no Chrome can not in a single externally triggered action send a MQTT message. *
Curl is just a command line HTTP client it can send any HTTP request possible by the spec, so without LOT more detail about what exactly you are using it for the next part of this answer has to be a bit of a guess.
If you scan a QR code containing a HTTP URL then this will most likely be passed to the built in browser on the device (or a WebView in the barcode scanner application). This URL will opened using a HTTP GET request (you can not change the HTTP verb, it will always be a GET).
You can encode variables into the URLs query string by appending them to the end of the URL e.g.
http://www.example.com?foo=bar
Would send a variable named foo with a value of bar and as long as you have room in the data you store in the QR code you can add as many of these as you want.
* Chrome could be passed a URL to a page that loads the Paho Javascript MQTT library that then sends a message via MQTT over Websockets if the broker supports it, but if you are going to do that you might as well have what ever HTTP server that you load the page from send the message.
I am currently having a problem with messenger bot development in which i want to get data from a url which shows in json format and then if a user types "show me the new news from university?" then it should get data from there and show. I don't know how to do this. please help.
Url for example : https://vitacademics-rel.herokuapp.com/api/v2/vellore/spotlight
If you haven't already, you'll need to get a server set up to listen for webhook events and send replies - Facebook have published a Quick Start guide to help.
Your bot will need to listen for an event, check to see if the user's message contains "show me the new news from university?", perform the HTTP GET request from the server side, convert the data into messages Facebook understands then send it. Exactly how you listen for events and perform the HTTP GET request will depend on the language and framework(s) you are using for your bot's server.
I think this is how should it work: I record the HTTP activity while browsing my website online. Then, When running my website's HTML offline, no network activity is made. And when a request is made, a response is retrieved from the recorded log.
I need to know how can I make this.
I think this tool is little near from what I want to do. But, unfortunately I don't know how to use it for my case.
The fact that you tagged this post with Fiddler suggests that you know that Fiddler can already do this using the AutoResponder tab. You may wish to update your question to explain why you don't want to do that.
I'm new to AJAX and PHP but I know that PHP is a server-side scripting language and so there will not be any changes to the html unless the user refreshes the page or the user submits a form. Therefore I suppose the change of the number in <span id="mercurymessagesCountValue"> when a facebook user receives a message
is AJAX-related.
And this is my guess:
The change of the number is triggered when it is detected that another user [the sender] has inserted a new row into a particular table and each column contains different data: the time, the message, the sender id and the receiver id.
So here's my question... In this case, how is the changes in the database detected and how does it trigger a javscript [or something else] to make changes to the html? Or if I'm wrong... can I know how Facebook does that? Thanks very much!!
If I got the question right, you should check out about pull and push models. Facebook works under the push model: facebook server knows when new message is received and it pushes the notification to the client (website open in the browser).
Let me clear a few things up for you here,
AJAX is simply a type of request being sent by the browser to go grab data from another page dynamically. In facebook's case, they actually have a special type of connection to the client computer to keep the page 'alive'. This way, they can push dynamic updates to the client without the need to constantly poll/refresh a single page on the server (would make large amounts of load).
So, let's just pretend, they are constantly refreshing the page on the server to determine how many notifications are unread -
Client -> Ajax Call -> Server PHP Page -> Ajax Return -> Client
So, in order, the client sends a request for the page to be generated by the server.
The server's php page will then count the number of 'unread' notification rows in the database for that particular user. It will then output the number of unread rows in plain html.
The client then recieves this plain HTML from the Ajax call, and simply updates the DOM with the new number of unread notifications
PLEASE NOTE: This is not how facebook works, but it's a good example of how to set up your own basic notification system if you are new to dynamic coding.
My guess is that requests are sent frequently from the client via Javascript, to the host, asking "has anything new happend since last time i asked?". The answer is responded by the server, with PHP, if it is yes, the new data is delivered in the respond and JavaScript updates the DOM (HTML) with the new data, like showing the red flag or something.
javascript:location.load(t);
(t=time interval)
i guess ,, refreshing a page in every several seconds will pop up the notifications recieved..!!
Our Architecture is using a Push Engine to send data to the browser ,
Could anybody please tell me what is the use of Push Engine ??
( Why is it required , as the same thing can be achivied using a normal AJAX programming )\
Please guide me .
let's say your visiting a website, and the website is updated continuously. Your browser needs to keep updating the data that you're viewing, meaning that the browser needs to keep communicating with the server, and get the updates.
you can use ajax to make requests every few seconds, each time fetch more data from the server. Problem is - you need to make a lot of ajax calls, and you open a connection (a socket) for each, and eventually, it is a very slow process. if the interval between the requests is large, you will have a delay between the updates on the servers, and the updates in your browser.
to solve that, we can manipulate the HTTP calls - keep the request (the connection) open, and continuously send data. that way, when the server wants to send something to the client (browser), there's an open connection, and it doesn't need to way for the next ajax call by the browser.
HTTP servers have a timeout on the requests, so just before request times out, browser will close it and make a new one.
another (better) method is using XMPP protocal, which is used in chats like facebook's and msn.
AJAX is a pull method - it requires the client to connect to the server. If you have some information that you want to display live - for example a live score in a football game - the AJAX call has to be made at regular intervals - even when there is no data waiting on the server. A Push Engine is the reverse - the client and server maintain a connection and the server pushes data when there is data to be sent.