How do applications know when new data is available on a server? For example, Facetime or skype knowing when a call is coming in, iMessage knowing when a new text is available, etc. I know the client is not just continually polling the server over and over again, so how is this done normally?
Such protocols send a real-time notification to the client telling it what is happening.
Related
From my understanding you cannot socket a connection between two iPhones (correct me if I'm wrong). So what I would like to do is have one server sitting between the client application that accepts messages and redistributes them to the appropriate person(s). Essentially the application is going to allow people to have a shared map that has their locations and everyone can annotate it.
1) I have been reading and researching into the CFStream class, but I'm curious to know if it might be better to just use the C send() and recv() functions. They almost seem much easier to use. What does CFStream offer over the native C socket functions that make it a better option?
2) Since I need the phone to actively listen for updated shared user locations/new annotations from other users, my plan was to periodically have the phone poll the server for any "news" from other users (say every minute or two). Is there anyway the phone could spin off a new thread in the application that is constantly waiting for incoming traffic? It would make life easier to be able to have a user annotate the map, push that to the server which then immediately updates the appropriate users maps.
I have been using example socket code from Jonathan Zdziarski's iPhone SDK book from O'Rielly Media to just try sending messages between a server and iPhone emulator (the classic knock knock joke server/client). However, after sending 1 or 2 messages the server gets stuck "receiving." The code runs perfectly when not sent from an emulator, as I can seemly spam the client send function and get a response from the server each time. Could the server be hanging because I use send() and recv() instead of the CFRead and Write stream?
You can socket iPhone applications using bonjour, or even GameKit (which is what I use because it manages all data for you).
Im developing an iPhone app with client-server design, the server manage client connection with sockets and keep an array of all the currently connected clients.
This way i get persists connection between client and server, and i can send messages from the server to the clients when ever i need.
My problem is on the client side, the iPhone user. every time the phone get locked the connection is lost so i need to re-connect and re logging again when the user unlock the iPhone.
Is this the way to go? Or am I doing it wrong? please help..
A RESTful protocol may be more suitable for mobile use.
I understand that some applications need to check against a server periodically, but why don't servers let a mobile device know when it's time to update.
For example, let's say you receive an e-mail in gmail. As it stands now, there can be a delay between receiving the e-mail and your device notifying you. I assume this has to do with waiting until the device has checked the gmail server, at which point it sees the new e-mail and notifies the user. It makes more sense to me that when the gmail server receives an e-mail, it should ping (or however the creator wants to implement it) all registered devices to let them know that it's time to update. This way notifications would be synchronized and mobile device could save battery by not having to periodically check a server.
What you are describing is called a "server push". Some mobile applications does use server push. And Google actually have a technology in place to make this easier to implement, named "Cloud to device messaging" (C2DM). It works by having the servers sending a tiny little message, via googles C2DM servers, to the application running on the device, informing it its time for a update. And the device then retrieves the actual update from the original server (not from C2DM).
Its good stuff. It allows the service listening for C2DM manages to wake up the phone and everything. The downside is, the user of the application needs a google account. For android users, this isnt really a downside though.
Except they do, in some cases. In the "Mail, Contacts, Calendars" section of Settings on my iPod, there's a submenu labeled "Fetch New Data", which contains an option to have the mail server or whatever "Push" the data to the iPod. The Fetch aspect, which you can set the schedule for, is for when Push is off or you're syncing with applications that don't support push.
That is how Android does it. It pushes notifications to the device and that api is open to third party developers as well so they can push notifications to their users.
That thing is it is difficult to know the address of a mobile device at any particular time, the I.P address is dynamic, on a server the address is much more stable, so the device knows it will always find Google at google.com but Google has no real way of knowing where to find the device, it wouldn't know where to ping in the first place.
This is where push comes in, there are different implementations but i think they work by having the device maintain a connection to the server, and reestablishing it if its lost.
See http://en.wikipedia.org/wiki/Push_technology
This of course is much harder to implement and maintain then a simple client pull.
I want to write an iOS app that can act as a client and a server to other iPhones over the cellular data network (i.e., without a typical centralized server). The goal is to share series of about 200 short event messages, one at a time, from the iPhone server to multiple iPhone clients by some means of notification. Apple Push Notification service would be fine for such notifications, but there is no need to use it specifically.
I think sending push notifications from one iPhone to another is possible by connecting to gateway.push.apple.com from the serving iPhone as described in the Local and Push Notification Programming Guide, but I can't find anyone else discussing this approach (maybe it's too obvious?).
The reason for all this is an attempt to avoid the overhead of infrastructure. If this isn't feasible, alternatives which minimize or avoid additional hardware are welcome.
Requirements:
Communication must be [strictly] over cellular data network
Wi-Fi isn't available
Bluetooth doesn't have enough range
Unidirectional communication with an iPhone server multicasting to many iPhone clients
No jailbreaking
Ideally the serving phone's battery will be able to handle this without a recharge
Update 5/4/11 2:12 AM EST: Just to be clear, I don't have any particular requirement to use APNs; I thought it may have been feasible in this setup, but from the discussion below, it sounds like that's not the case. However, I'm still interested in any other system that could help me achieve the same end result with some type of message passing or similar form of communication.
Theoretically you should be able to write a iOS app that can connect to the APNS and send notifications to other devices running your applications. However, your main problem will be to actually acquire the 'tokens' of other devices. When you have a centralized server doing the job, its always online and thus, the clients can 'talk' to it via http and register them self (giving their tokens to the server in the process). Thus the server knows the client token and it can use them to send notifications to the clients via APNS.
However this is not possible in the scenario you are talking about. But this is not to say its impossible. May be you could use an email account X, to store all client tokens. Every client will send a email to this account with their token in it. So when a another 'client' want to send a notification to another client, it can find out the token by reffering to the inbox of the email account (you can cache this stuff and optimize it in a zillion ways of course).
But the point is some how a (third party(ex: email service provider)/your own) server that is online 24/7 will be involved in the process.
Let us know how you progress with this. It would be interesting to know.
I am looking for a way to send data to a SPECIFIC iPhone application without going through Internet... thus using the mobile network.
Thanks.
No chance. There's only two things the phone is actually receiving: calls and text messages. Both cannot be used for what you like to do, since neither can be routed to any app.
You can't even really keep an open socket to allow connections through the internet, since the new multitasking is not really multitasking and allows listening for new data only for a few types of applications, voip clients for example. But you didn't want internet anyway...
Best you can do is text the phone a URL whose schema is registered to your app.