Using GCM in peer to peer chatting - java

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.

Related

How to config push notification on my own server?

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.

Is there a Java API for GCM Cloud Connection Server

I am just going through the new features of GCM Cloud connection server. On client side this seems fairly easy using the google play services, as described in https://developer.android.com/google/gcm/ccs.html, however for the server side it says:
GCM Cloud Connection Server (CCS) is an XMPP endpoint, running on
http://gcm.googleapis.com port 5235.
CCS requires a Transport Layer Security (TLS) connection. That means
the XMPP client must initiate a TLS connection. For example in smack,
you would call setSocketFactory(SSLSocketFactory), similar to “old
style SSL” XMPP connections and https.
CCS requires a SASL PLAIN authentication mechanism using
#gcm.googleapis.com (GCM sender ID) and the API
key as the password, where the sender ID and API key are the same as
described in Getting Started.
Does that mean I manually have to open a port and parse xml/json or is there some kind of Java API that I can use to implement the server side?
For the GCM Server there is a library, the javadoc is at http://developer.android.com/reference/com/google/android/gcm/server/package-summary.html
There is a demo server app Google has written here at http://developer.android.com/google/gcm/server.html
As I understand you can choose whether you want to use the XMPP service or the old HTTP service. Not sure what the advantage is.
You can use Smack library to work with XMPP in Java.
And here you can find an example code that sends notifications using GCM CCS.

Android Device act like Server

I working on one project which Android device is act like a Server. I mean, when I send any requests to my device, then I will get a response.
If any one have any idea so please tell me. I am waiting for the reply.
A server usually accepts request on a certain IP and Port. This is a problem for mobile devices, because usually they're on a private network (behind a router) and one can not address IP and port of a special device.
So, practically spoken, I really doubt that a mobile device can act as a server.
A reliable solution would require some sort of extra proxy server. Basically your mobile will connect with this "ground-based" server and the system of proxy and handheld is the server you're looking for. It is operational once the handheld is connected. Client establish connection with the proxy and send their requests, the proxy forwards the request to the mobile device to get a service response for the client.
A nice architecture for this approach is XMPP, the implementation of the proxy server would be a standard xmpp server (like openfire).

How should I go about implementing this SMS notification system?

I have developed a application which involves billing users. To do this i have incorporated a GSM modem (gateway) that the SMS messages are sent through. This SMS message is sent to the user when he is billed with the bill details. The GSM modem is connected to a single computer but the billing can happen in other systems. How do I send an SMS notification for the changes that occur in the other systems, as the GSM modem is attached to a COM port on the computer*.
can we access the COM port of other system or shoould i use socket programming (with the machine with the modem(Server) listening for any connection, the sender has to send data in particular format and the server has to parse the data and send the message) or use Java RMI or is there any other solution.
Suggestions please....
Thank you
There are any number of solutions you can think up. The most common ones would be:
Communication with some kind of RPC, be it RMI, SOAP, plain HTTP, telnet, etc.
Using an SMS gateway such as Nordic Messaging’s EMG (probably overkill, though) or kannel (seems to be down currently).
We've got an SMS Gatway. We wrapped it in a J2EE-application with a webservice interface. That way we can send SMS from any of our applications. For the sake of java we made a little jar-file that talks to the webservice
SmsClient smsclient = new SmsClient();
smsclient.sendSms(from, to, message);
I built a similar system to this in the past where small embedded systems sat on a network and reported messages over the network to a central server that logged the messages and sent SMS messages when required.
I used a java socket listener that waited for UDP messages from the embedded units and the java program wrote to the GSM modem on the servers comm port. UDP was only used instead of TCP as it was simpler to configure on an embedded system.

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