How do I check a html file on the internet if it has changed ? But it may not check the first 3 lines for the updates because it displays the time. The website does not use mysql or sqlite database. And is has not got a RSS feed system
Normally, you add this header line in the request:
If-Modified-Since: Sun Nov 6 08:49:37 1994
and then the server determines if the web page has changed since then, and return a 304 response if not. If the web page is generated by a CGI script, then it will be up to that script to decide if the page has changed.
Since you say the first three lines of the web page display the time, I assume the web page is generated by a CGI script of some sort. You haven't said what language that script is written in, but in any event, you'll need to grab the If-Modified-Since header from the request, parse the date, and decide if the content of the page has been modified since that date.
Does it have to be every 15 minutes? If what you're really looking for is notification every time an HTML page changes, you should look at Google Cloud Messaging (GCM). This system generates a notification that's sent to your app by a server.
GCM has advantages that may not be obvious. The biggest one is battery life; constant polling drains the device battery. In comparison, GCM messages are received instantly while the device is connected to the network but not actively sending. In addition, GCM messages are queued and combined, so when the device is offline and then comes back online only one message is sent.
GCM also ensures that your app only uses the network when it has to get data. This allows other apps to use the network more readily.
Related
I want to implement something similar to the Stories feature in Facebook or WhatsApp.
Possible approaches :
At first, I wanted to open a web socket so I could receive the latest Stories updates (new story from a friend, or if a story was removed).
There'a another alternative - getting those updates using FCM pushes.
A service which receives the pushes broadcasts the "new story"/"story removed" broadcast using a LocalBroadcastManager, and the suitable activity which is registered to this broadcast receives that update.
Using the push approach, it would mean that even if the app is killed, the push can still be triggered.
It seems a bit of a waste.
But considering that there might slow connection, connection drops, etc., the websocket is also quite "vulnerable".
Also, what if 24 hours of a story expire, how do I make sure I always remove that story from the Stories list view and not keep displaying it ?
With a socket, we may lose connection. if we reconnect after we were to supposed to be notified that the Story time expired, we would still display that Story.
Just store the stories in some sort of database, together with their creation dates. A client can then periodically fetch for new stories. Based on the creation date, the client can calculate the age of the story and decide to show it or not.
If a story has been seen by the client, he can store that information in local storage so watched stories can be displayed as old stories.
Now for the cleanup part, there are two options. Either you write a program that runs on a server 24/7, that like a client, periodically fetches the stories from the database, checks their age and deletes those which are too old. The other approach would use the same concept, but all normal clients delete old stories from the database.
The second option would be very insecure though, because the age calculation could be manipulated on the client side, either by mistake or by an attacker.
I am new to mobile development and I undertook some freelance work. Now I am required to display a page with top N nearest places (businesses registered with us).
I am wondering what the best way of going about this is, from my experience it would seem that I would want to do this calculation in my back-end server.
I have a NodeJS server, however, it seems the server will be concurrently doing a lot of other work just verifying JWT tokens and what not, I have seen that android provides a method to easily do these calculations (Location). I have also read that there are some google API's one could use.
The idea I have is that I can pull my places with their lat, long from my database then the user sends lat,long and my server calculates top N results and sends to user.
What would you recommend and why?
Thanks!
The short answer is: Server.
But why?
The job of the server to make it so no one can use the app who is not authorized to do so. Thats one of many jobs anyway. However, you should send your location to the server, the server makes the API call, and returns the N closest locations.
You take that response, parse it, and fill in a view as you would like. With the server doing the heavy lifting, you can then also keeps track of something better, like how many calls, which calls, location of calls, etc etc.
I am working on an Android APP that will handle multiple email accounts, POP3 and IMAP. The current APP, to check for email, you open the APP and click on an update feature. That logs into each email account, and checks for any new mail. Although this works, we need a more efficient, and timely check for new messages.
At first I thought PUSH was the way to go but from what I have read on here, that may not be ideal... especially with multiple IMAP accounts. If I understand right, it keeps each IMAP connection open long-term which could cause some other issues and not sure I could even use it with POP3 accounts.
I looked into POLL as an alternative but that too has potential issues. That involves how frequent it fires up and does the account "checks", the amount of time that takes, and how that all effects battery life. In addition, there appears to be several different "ways" to schedule the POLL option (AlarmManager, JobScheduler, and SyncAdapter)... and I assume one might be better than the other... especially with new version of Android that let you "quiet" your device at certain times of the day.
So the question is, based on what we are looking to do, which is the better way to handle this capability? I am leaning towards PUSH (which format...still unsure), but don't want to waste hours of time to find out that I went down the wrong path.
Thanks ahead for any advice.
IMAP supports IDLE Command in which client acts as passive entity depending/relying upon the server to notify arrival of new mails in account. But as you correctly figured out that it will keep connection open and other issues of rebuilding the connection if it gets disturbed due to any possible reason.
POP do not provide such passive capability to clients. Clients have to pull the mails from server.
From my experience, total synchronization of account on client side is not a problem but it requires too many things to be taken care of like parsing the mail content, maintaining the active list of mails in an account's folder, etc.
[1] Very simple synchronization mechanism would be to simply show the MailList and whenever a message is clicked upon then dynamically load the content of mail.
MailList = Sorted order of Mail Entries in an account's folder.
Single Mail Entry = Sender + Mail Subject + Mail Date & Time + Mail Size
This method of showing MailList initially and fetching the mail content on demand can be achieved via both:
IMAP (FETCH Subject, INTERNALDATE, Sender, Size) and
POP (TOP n m {TOP is a POP command which can fetch m number of lines of nth mail's body along with complete MailHeaderSection of nth mail}). Afterwards MailHeaderSection can be parsed and MailList can be constructed.
[2] Simply fetch the complete mail and store accordingly. Now, Parse it on demand and show it to user. This is also readily supported in both:
IMAP (FETCH BODY.PEEK[])
POP (RETR n)
I like this method since its simple.
Both the above methods are working as if client is active entity (pulling mails on demand).
I'm working on a chat Application like Telegram. The user should see his/her friend availability (Online/Offline). I searched a lot and found out that the server must send ping to the devices and devices reply back. But I think it prevents the app to use the server and device resources optimally. You suppose there are a million of users, lots of pings in every interval, lots of device battery and bandwidth use and so on.
I also studied Firebase and GCM. They check device availability to send messages to them, but I can't use it to show it to the users.
I'm really interested in technology that Telegram used for users availability.
Please let me find an optimal way.
Thanks
If you look at the blog post #Andre linked to, you'll see that the "official" Firebase approach to this problem is to store a value in Firebase's Realtime Database that indicates the status of the user. So, the logic is this:
use a property in the database to keep track of a user's status (e.g. /users/{uid}/status)
when a user logs in you set their status to "online"
when the user logs off/puts the app to the background/is idle you change the value of that 'status' property (e.g. to "offline" (use .onDisconnect() method as shown in the blog post).
Now, whenever you fetch the value of that status it'll always reflect the user's online/offline status without relying on the user actually being online at the time.
If you want to show a user the status of all their friends you simply loop through a list of their friends' uid's and get the relevant status for each. All the info/code seems to be in that blog post.
I am working on group chat app using Smack 4.1. I am able to differentiate between history messages and current messages. but problem is which one to show the user, For example in history messages there is time stamp based on it i can show it to user and can avoid repeating. for current messages there is no time stamp so I am taking device time stamp but device time stamp is different with respect to server.
For server time sync, check this XEP: https://xmpp.org/extensions/xep-0202.html and as per openfire supported XEP's document, this XEP is available in Openfire.
You can send an IQ with specified name space to your XMPP Server and in response you get time of server, now you can calculate time difference accordingly