L
L
LyoneNET2015-01-10 15:51:13
Android
LyoneNET, 2015-01-10 15:51:13

How to request data from the site with a certain frequency?

How the mechanism for requesting data from a web server works. That is, for example, as in mail applications, when a message arrives at an email address, it is also displayed in the program.

In general, how to properly monitor data on a web server?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
GavriKos, 2015-01-10
@LioneNET

Options:
1) In a separate thread, every n seconds send a request (GET / POST) to the server and see what he answered you
2) Open a socket connection with the server and wait for it to send you something.

A
Alexey Nemiro, 2015-01-10
@AlekseyNemiro

Too general question.
Client programs simply perform checks at a specified frequency (by timer). For example, a mail program can make requests to the mail server every ten minutes and, if there are new letters, download them.
On websites, when using AJAX , this works similarly. The page loaded into the browser periodically makes requests to the server (in the vast majority).

function Checker()
{
  $.get("http://localhost/естьчо", // проверка наличия данных на сервере
  function(result)
  {
     alert("что-то есть");
     window.setTimeout(Checker, 5000); // вызов функции Checker через 5 сек.
  });
}

window.setTimeout(Checker, 5000); // вызов функции Checker через 5 сек.

It is possible for the server to notify clients when new data arrives, but this is a little more difficult to implement.

A
asd111, 2015-01-10
@asd111

Websockets, server sent events, ajax - three ways.
www.html5rocks.com/en/tutorials/websockets/basics
www.html5rocks.com/en/tutorials/eventsource/basics

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question