How to config push notification on my own server? - java

For Some reasons , GCM is not my target !
i'm trying to push notification from my server to android application , do i need use Sockets ? , when we use sockets , user is always communicating to server but i am just looking for this :
"server aware user for notifications , user request notification from server" no more data transfer or "keep-alive" connection

If GCM is not your target, then go for TCP Sockets
Create persistent TCP Connection from device to Server.
Design custom protocol for notification subscription and un-subscription. And Push messages to the respective devices.
Points to Note:
Your application won't be able to maintain persistent TCP connection
when device is in power saver mode.

Related

How does whatsapp instantly receive a message?

I'm trying to make a communication between my App and the server side. The app needs to receive messages from the server because it's remotely controlled. It works as a Background Service.
I'm currently getting the messages from the external MySQL by using HTTPPost, doing requisitions every 20 seconds, but it spends much battery.
I tried doing a Socket connection to a server (build in java): device connects to the server every 20 seconds and close the conn when it just receive the data, but it also spends much battery.
Is there a way of receiving these messages instantly as Whatsapp does?
If the app is open it's most likely a socket connection. This is usually how messengers work.
In the background though it's most probably using push notifications (Check FCM - Firebase Cloud Messaging). This source of info can be unreliable so making a service with requests once a minute or two could be cool
In our messenger, we use long-live HttpsURLConnection as the main channel. The connection is hosted in Service and it is run in separate thread. In case of disconnect, we try to establish a new one. And we stop the service after our application is inactive for 2 minutes.
As the second channel, we use FCM.
This is what concerns messages. We also use WebRTC for multimedia data transfer. And we are going to use SIP calls to init voice- and video- call.

Using GCM in peer to peer chatting

How to make peer to peer chatting using GCM?
I know we could use GCM in push notifications from server to devices But is it possible to use it to send messages from one device to another.
Thanks
No, per the GCM Architectural Overview, GCM only handles two things:
Registering your application with the GCM service
Allowing 3rd party servers to send messages to registered devices
Of course, you could connect directly to your 3rd party server, get a list of registered users, then send a request to your server to message that user via GCM, but that is not a peer-to-peer device to device connection.

Android, Java Socket

I have created a TCP socket client in android and use a open src socket app which i use as a server to send messages to my android app, every thing works fine.
But the doubt is that both device are present using my home wifi connection hence having 192.x.x.x series ip,
But in case my device is connected to wifi router in my home having Ip of 192.x.x.x and server is having static Ip, will my server be able to send message to the remote device, irrespective of the fact there the device is having local network Ip ?
No, you won't be able to send data to the remote device unless and untill it initiates the connection , you cannot initiate a connection to a dynamic Ip(remote Device
)

Android continuous tcp polling

I am working on a project in which I can see webcam images from the people who is in front of the door on my Android app.
But I am getting a bit confused. I've managed to setup a connection with a service on my phone to a server which handles the image sending.
But i only want to get images from the server when someone presses the doorbell, so I need to send a notification or something to my app so I know there is one in front of the door, and I want to decide if I want to answer his call or not.
Now this is why I am confused: if I open the tcp socket in the android service, how can I know that my server sends a 'call' message, because the tcp socket is openend when the service is created. Do I need to keep polling every second? Then there is still a little chance that I will miss the call message?
Or do I have to run the application as server and the doorbell as client, so the client request a connection?
Have a look at cloud to device messaging, c2dm , a lot more power efficient too. Built into android.
https://developers.google.com/android/c2dm/
If the tcp socket is opened when the service is created, just send some appropriate message from the server to connected clients. If your client is connected, it will get it. You only need to poll if the client continually connects and disconnects, eg. like many HTTP 1 web services.

web server sending command to a J2ME app

Can a J2ME app be triggered by a message from a remote web server. I want to perform a task at the client mobile phone as soon as the J2ME app running on it receives this message.
I have read of HTTP connection, however what I understand about it is a client based protocol and the server will only reply to client requests.
Any idea if there is any protocol where the server can send a command to the client without client initiating any request?. How about Socket/Stream based(TCP) or UDP interfaces?.
If the mobile device doesnt allow you to make TCP connections, and you are limited to HTTP requests, then you're looking at implementing "long polling".
One POST a http request and the web-server will wait as long time as possible (before things time out) to answer. If something arrives while the connection is idling it can receive it directly, if something arrives between long-polling requests it is queued until a request comes in.
If you can make TCP connections, then just set up a connection and let it stay idle. I have icq and irc applications that essentially just sit there waiting for the server to send it something.
You should see PushRegistry feature where you can send out an SMS to a specific number have the application started when the phone receives that SMS and then make the required HTTP connection or whatever. However, the downside of it is that you might have to sign the application to have it working on devices and you also need an SMS aggregator like SMSLib or Kannel
You can open socket connection and implement "Hide" (or "Minimize") functionality in your app. Call this to hide:
Display.getDisplay(MyMIDlet.instance).setCurrent(null);
Listen to the server in a loop, and if you receive some message, popup the applicaion by calling this from canvas:
Display.getDisplay(MyMIDlet.instance).setCurrent(this);
But it dosen't work on all devices.
Socket push are supported by j2me. But it could work only if your server could deliver data to your mobile phone. Most likely that operator gateway don't allow to do this.
Maybe it would be possible if your mobile has static external IP address - some operators could provide this for $$.

Categories