Send data to specific device without GCM - php

I'm looking for the best approach to send data(String) from my server (PHP) to one specific android device.
I can check the device if is online/offline on my server(with http-post method). But I don't know how to send data to spesific device without GCM. (I'm not looking for push notification and I'll send message to maximum 100 user.)

Without using GCM, you have several options:
app polls server for updates, at a specified interval. It may impact device's battery life and network usage.
app opens TCP connection to the server which is then used by server to send updates to app. I'm pretty sure it's not something you want to do in PHP, though.
server sends an SMS to the device (assuming it's a phone) and app intercepts it. This would require your server to know the phone number of the recipient and implies using some SMS API (usually paid).
app (WebView or web app) uses WebSockets to connect to server
use push service different than GCM (i.e. Urban Airship)
From all of those I would look into polling first. It's often considere somewhat a bad practice, but it's not necessarily the case. Have a look at this AT&T blog post for some measurements.

An other solutions is to use an MQTT .
Install MQTT in your server and create your queue.
Write to the queue in PHP with one of the PHP libraries : https://github.com/mqtt/mqtt.github.io/wiki/libraries
In Android receive the message with http://www.eclipse.org/paho/clients/android/
The communication is asynchronous and all work inside your LAN without external public service (like GCM).
I hope this can be helpful.

Related

Send commands from a server to swift app

I am new to swift and was wondering how could I send commands from a server to my iOS application ? For example imagine a website where I can click a button and that button would then trigger a pop up to all users of my app. Is this possible and if so can someone lead me in the right direction?
Much appreciated
Yes, you can
Silent Push Notification: Send a Silent Push Notification and handle in your app. But you need user permissions to receive Notifications. Add "content-available" : 1 to your notification content.
Using Sockets: There are many options to create connection b/w device and server. example: https://socket.io/
It depends what you are trying to do, you might want to look at apple push notifications and see how they work. From there I would suggest looking into sending notifications to the apple server (that would send the push notifications to the app). I hope this sends you in the right path good luck!
I just assume that you have an application that a number of users are using and you have a web application that can show all mobile users.
For the most of cases, whenever a user is using the application, you let the application send a request with your user's information to your server and your server records the user information in the database.
When your website wants to show all the users' information, it just fetches all the information from the database instead of sending sort of commands to all applications to get information in real-time.
Of course, there is a more complex way to send commands to all running applications to get the results. However, it requires both server-side and client-side (ios application) implement functions sending commands in real-time using Socket or MQTT etc. This is more complex and it requires iOS application running in front or background at the same time.
I assume that using HTTP to record every mobile user is more suitable for your case.

How to implement push notification in cordova with angularjs using php json array

I have a project were I am required to add push notification for Cordova AngularJS Push Notification using PHP on server side which gives JSON array as output. I can implement chat etc using this, but I want to know how to implement it in push notification or accessing native app API. Firstly I thought using Javascript SetInterval, but it slow downs the app, and checks the API everytime...
For Cordova push notification you can take a look here:
http://phonegappro.com/tutorials/apache-cordova-phonegap-push-notification-tutorial-part-1/
Still, let's review some other methods of sending data to the client using Web APIs:
Long polling - keep the connection open on the server side with no or long timeout, and return a result when you want to send a push notification.
Use WebSockets - open a steady TCP connection to the server and transmit messages in both directions (unlike HTTP's request/response model).
Use PushManager - this is an experimental technology that is not yet supported on mobile devices, so I guess this is a no-go for you.
Use simple polling - every now and then poll the server for a new message.
Long polling and Web Sockets will overload the server if you'll have a lot of concurrently open connections, so I wouldn't go there. Also Web sockets are mostly used for communicating between clients (server passes the client info to both clients, then they can communicate on their own without the sever intermediating between them).
PushManager is too new a technology not yet supported in mobile.
For what you want (mobile I guess, as you want to use Cordova), and without knowing what you are actually trying to achieve, I would say go with #4. I understand you already tried it, but perhaps try to lower the polling rate to every 30 seconds or so.
I understand that while debugging it doesn't seem nice to send something from the server then wait the better part of a 30 seconds period until it appears on the client, but if you think of it from the user's view point you'll see that the user doesn't know when the server sends the data, so it does appear immediate.
However, if you're writing a chat client, then I would go with web-sockets, using the server to connect the two (or more) clients in the chat and letting them pass the messages directly. If you want the chat to be server backed, just periodically send the transcript to the server using simple AJAX.
DIY vs Hosted Realtime Data Stream Network Service
If you do not expect to have more than a few thousand clients using your app, the DIY (do it yourself) sockets technologies (WebSockets, Socket.io, etc) is feasible. Beyond a few thousand (many of our customers say in the range of 5 to 10 thousand) you will experience difficulty (and large expense on server resources and scalable code) scaling your service.
Using a hosted realtime data stream network service like PubNub, Pusher, Ably, etc will be less costly and complex and it will just work. With some of the hosted services (PubNub for sure - which I work for - full disclosure) provides the ability to publish the message in realtime and include a push payload (for GCM, APNS and MPNS) that will also send the push notification if the app is in the background or not running.
With PubNub BLOCKS, you can also implement server side code that runs in the PubNub Network to inspect, manipulate or process the message without having your server do the work. This means you could send the message to other third party services: translate message to another language, use AI services for whatever reason, send an SMS/email/etc and much much more.

how to get value from database in php by sending sms from device

I am developing an android application in that when internet connection available i directly communicate with database using J SON parser and with use of web service but when no internet connectivity then i need to communicate with database by just sending text message is there any way for such communication??
You could use an SMS API that provides virtual numbers. Generally speaking they turn an inbound SMS (sent to a virtual number you lease) into an HTTP request.
So from your mobile app, you'd do whatever is needed to compose / send the SMS payload, using your virtual number as the recipient.
Server side you just need to accept the callback form the API, and parse the incoming message for the payload, and (I assume) use the sender to identify the user behind it.
You should check out Nexmo (disclaimer: I do some developer evangilism for them), they're one of a few API's that provide virtual numbers for incoming SMS. Their pricing model would work out very well for your use case, as all inbound messages are free. You'll just pay a buck or so a month for the virtual number.
I've not added any documentation to this yet, but here's an example of something similar, the source just being an Arduino with an GSM module. The Arduino relays environment data to a web service, using SMS as the data pipeline. Same basic process you'd use: Data -> SMS -> Virtual Number -> HTTP Callback -> Web Server.
I don't think there is any way to hit URL via text messages.

whats the best way to implement real time push messages with apache, php and mysql only?

i'm trying to implement a chat application for android (where users can communicate people who are in same location). i'm thinking it of an facebook messenger with Geo specific oriented. i came across to terms like repeated pull, comet, bosh, websockects, socket programming, xmpp(which requires xmpp capable server like openfire) etc to do this. But my resources are fixed like apache, php (codeignter) and MySql only. I need to find the efficient to way to do this. Guys i need this. Please help me.
Thank you,
abbiya
The preferred approach on Android is Google Cloud Messaging.
Google Cloud Messaging for Android (GCM) is a service that allows you
to send data from your server to your users' Android-powered device.
This could be a lightweight message telling your app there is new data
to be fetched from the server (for instance, a movie uploaded by a
friend), or it could be a message containing up to 4kb of payload data
(so apps like instant messaging can consume the message directly).
The GCM service handles all aspects of queueing of messages and
delivery to the target Android application running on the target
device. GCM is completely free no matter how big your messaging needs
are, and there are no quotas.
Essentially, it works like this: Your server talks to Google, and Google pushes the message in real-time (or nearly so, as long as the device is powered on and connected to the Internet) to the Android device(s). There's a registration process that happens on the Android device the first time the app is installed (and at future points to revalidate the registration). In your Android app, it's your responsibility to send this registration ID to your server so you can store it for future use. Your server uses this registration ID when it wants to push a message to that device.
The communication protocol between your server and Google is JSON over HTTPS. Your server can use any languages/technologies, as long as it can communicate with Google's servers. A PHP/MySQL application can definitely meet the basic requirements for the service:
Before you can write client Android applications that use the GCM
feature, you must have an application server that meets the following
criteria:
Able to communicate with your client.
Able to fire off HTTPS requests to the GCM server.
Able to handle requests and resend then as needed, using exponential back-off.
Able to store the API key and client registration IDs.
On the client side, the Android device must be running API version 8 (Android 2.2) or later. Of course, it's also your Android app's responsibility to process incoming messages (using a BroadcastReceiver, as the Android system sends an Intent to your receiver whenever a message arrives), which allows you to handle messages however you want.

Making Android chat application from scratch

I need to make chat application for android. I thought of using PHP script to implement the chat application. Basic idea is to send message form android client to PHP script and making use of PHP script send the messages to the MySQL database. These messages will be broadcasting to other people. But the problem is auto broadcasting messages to other people. Is there a way to do this using android and php?
You can do the following
Make a persistent tcp connection between your device and the PHP server
When a message is broadcast send it over the tcp connection of each device
On the device process this notification and you are good to go.
If you want to use Java on the server side I have your project already finished and ready to ship ;) (just kidding)
But if you are interested check out the Device-To-Device messaging framework of OpenMobster Mobile Cloud platform. The project is free and open source. Here is a link to the Device-To-Device Framework: http://code.google.com/p/openmobster/wiki/D2DPushFramework
and http://code.google.com/p/openmobster/wiki/PushFramework
The above three steps are already taken care of by the framework. The developer just has to focus on the App itself
Good Luck!!!!
Yes there is several ways to do this
you can just post to the server and from the server send push notifications to the mobiles
You can make the mobile keep checking for updates if it exists
You will require to finish these steps ( at least ):
setup a PHP web server
register for Android Push Notification (you probably need that)
create database schema
write your own codes to allow users to submit & retrieve chat messages
security !!!
You'd probably want to use Google's C2DM, though it's not free.
Your php server would get a message from a phone, do it's processing, then make a HTTPS request to Google's C2DM service, which sends the messages to the destination android device.
http://code.google.com/android/c2dm/#push-process
Don't use C2DM, its a deprecated. Please go through the GCM(Global Cloud Messaging),
please follow this link,
http://developer.android.com/google/gcm
Have you heard of Firebase? Firebase. Making a chat app with Firebase is like eating pizza.

Categories