polling

How to wait for a WebSocket's readyState to change

戏子无情 提交于 2019-11-27 03:39:46
I'm trying to implement a WebSocket with a fallback to polling. If the WebSocket connection succeeds, readyState becomes 1, but if it fails, readyState is 3, and I should begin polling. I tried something like this: var socket = new WebSocket(url); socket.onmessage = onmsg; while (socket.readyState == 0) { } if (socket.readyState != 1) { // fall back to polling setInterval(poll, interval); } I was expecting socket.readyState to update asynchronously, and allow me to read it immediately. However, when I run this, my browser freezes (I left it open for about half a minute before giving up). I

jQuery AJAX polling for JSON response, handling based on AJAX result or JSON content

我的未来我决定 提交于 2019-11-27 02:40:24
I'm a novice-to-intermediate JavaScript/jQuery programmer, so concrete/executable examples would be very much appreciated. My project requires using AJAX to poll a URL that returns JSON containing either content to be added to the DOM, or a message { "status" : "pending" } that indicates that the backend is still working on generating a JSON response with the content. The idea is that the first request to the URL triggers the backend to start building a JSON response (which is then cached), and subsequent calls check to see if this JSON is ready (in which case it's provided). In my script, I

Comet VS Ajax polling

被刻印的时光 ゝ 提交于 2019-11-27 01:46:55
问题 I need to create a chat like facebook chat. With Comet I need more memory to keep the connection. With Ajax polling there is a latency problem if I send request every 3-4 seconds. So... If the latency ( 3-4 seconds ) doesn't matter, Is Ajax Polling better for my case ? 回答1: Latency is not the only problem. COMET (long-polling) "saves" your traffic - when you use polling, you cannot know, if there were changes on the server, so some of the calls may be just a waste of traffic and resources (e

Socket connections and Polling. Which is a better solution in terms of battery life?

南笙酒味 提交于 2019-11-27 00:08:39
问题 So... I'm making an application for Android. The application needs to send and receive realtime chat data (needs to be a socket) but it also needs to send commands (which don't as the client knows when it is sending something). I need to know what is a better solution in terms of saving the user's battery. a) Opening and Closing the connection every time a command is sent, if the chat tab is opened then keep the connection constant. b) Keep the connection constant all the time. I've taken a

How does push notification technology work on Android?

空扰寡人 提交于 2019-11-26 23:25:18
How has Google implemented their push notification feature? Does it work through polling done by a service running in the background or in a different way? Tal Kanel From what I've heard during an Android developers conference in Israel: There is simply a TCP socket waiting in accept mode on a cloud Google server. The TCP connection had been initiated by the Google Play application. That's why Google Play must be installed on the device for making Google Cloud Messaging (GCM) (formerly Android Cloud to Device Messaging Service - C2DM ) work. When this TCP client socket receives some message,

Getting historical data from Twitter [closed]

爷,独闯天下 提交于 2019-11-26 18:24:37
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . For a research project I would like to get the last 3 months worth of Twitter messages. Technical challenges aside, is this possible? by using some sort of slow polling mechanism to keep the rate limiter at bay? The Twitter API states "Clients may request up to 3,200 statuses via

Server polling with JavaScript

半世苍凉 提交于 2019-11-26 16:11:19
What is best practise for polling server with JavaScript for application that needs to refresh data very rapidly? I'm using jQuery for front-end and Java Spring Framework for backend. Example of refreshed data could be list of items that are getting updated very rapidly (every 1 second). Daniel Vassallo You may want to use jQuery's Ajax functions to poll the server every second or so. Then the server can respond with instructions to the browser in near real-time. You can also consider long polling instead of the above, to reduce the latency without increasing the frequency of the polls.

How to wait for a WebSocket's readyState to change

…衆ロ難τιáo~ 提交于 2019-11-26 12:39:45
问题 I\'m trying to implement a WebSocket with a fallback to polling. If the WebSocket connection succeeds, readyState becomes 1, but if it fails, readyState is 3, and I should begin polling. I tried something like this: var socket = new WebSocket(url); socket.onmessage = onmsg; while (socket.readyState == 0) { } if (socket.readyState != 1) { // fall back to polling setInterval(poll, interval); } I was expecting socket.readyState to update asynchronously, and allow me to read it immediately.

Serial Port Polling and Data handling

帅比萌擦擦* 提交于 2019-11-26 11:19:18
问题 I am trying to read from several serial ports from sensors through microcontrollers. Each serial port will receive more than 2000 measurements (each measurement is 7 bytes, all in hex). And they are firing at the same time. Right now I am polling from 4 serial ports. Also, I translate each measurement into String and append it to a Stringbuilder. When I finish receiving data, they will be ouput in to a file. The problem is the CPU consumption is very high, ranging from 80% to 100%. I went

jQuery AJAX polling for JSON response, handling based on AJAX result or JSON content

我与影子孤独终老i 提交于 2019-11-26 10:13:07
问题 I\'m a novice-to-intermediate JavaScript/jQuery programmer, so concrete/executable examples would be very much appreciated. My project requires using AJAX to poll a URL that returns JSON containing either content to be added to the DOM, or a message { \"status\" : \"pending\" } that indicates that the backend is still working on generating a JSON response with the content. The idea is that the first request to the URL triggers the backend to start building a JSON response (which is then