I want to develop a simple push notification system for various android devices.
After two days of documentation i've found very interesting to use MQTT protocol.
System needs:
- an MQTT client on Android: eclipse Paho seems to be a good solution
- any MQTT broker you like for the server part: my attention is on Mosquitto cause is Open-Source
I've read documentation and the configuration file and seemed clear. The only thing that I couldn't understand is if i can manage topics (where clients subscribe to). In particular if i can create topics and how to.
Thanks.
It's not clear whether you mean on the client side or the broker side...
Assuming you mean the broker side, you don't need to create topics, they are created automatically as needed. You can control what clients have access to what topics using the built in authentication and ACL code, or you could use an authentication and access plugin. Writing your own is quite easy, or you could use the excellent https://github.com/jpmens/mosquitto-auth-plug
On the client side, simply subscribing or publishing to a topic is sufficient to create it on the broker, assuming you have permissions for that topic. This may not be the case in all MQTT implementations.
As an example, try subscribing to the # topic on test.mosquitto.org or iot.eclipse.org. These show a huge range of available topics and there is no admin to support them in the background.
This basically means that the only administrative load you have is restricting access on the broker where required.
Using code stole from somewhere, I made a pretty simple "MQTTMessenger" app for Android. https://bitbucket.org/mjgasner/mqttmessenger
From what I remember, you'll need to go into src/com/gasner/mqttmessenger/MessengerService.java
and change the host ip to the ip of your MQTT server.
For the MQTT server, I used Mossquitto server.
You'll also have to make sure you port forward port 1883 to the server.
I used this to send stock numbers to my phone. It's been almost 2 years ago, otherwise I could tell you more.
The C2DM directory is unrelated. It is Google's push notification service that I was also playing with at the time.
In the other directories at Bitbucket https://bitbucket.org/mjgasner are the .NET service and winforms app I wrote to communicate with the MQTT server. The service would accept the message from the android app through the server and reply with the stock amount it pulled from google's api.
If you have any more questions, comment below.
Related
I am using mqtt and mosquito broker to build a simple instant chat for an android platform. Now I wanted to implement a condition where any client can check if another client is online.
I know about Last will and testament but I wanted a user to be detected offline only wen the application is inactive or the user is not currently using the app.
I actually dnt need any code, buh wanted an idea as to how to implement this and I would be much grateful.
You can do this without relying on MQTT internals which is much easier in my view. With this approach, you have much more control over what is going on:
The client can periodically send a message within another topic to inform the server of its availability. In case the server does not receive that message after a specified amount of time, it can assumed that it is offline.
The client can also send another message if the user logs out and inform the server a well.
If you insist on using MQTT internal structure, you may find this question useful:
How to Find Connected MQTT Client Details
I am very new to jxfs things. I have a requirement to call jxfs server which is in cloud server from the jxfs client which is in ATM environment.. How can i call?.. I need to call this one through the Jxfs RMI concept. It would be appreciated one if any example code is available. If atleast you are having code for calling from jxfs server to jxfs client, please post it.
Thanks in advance guys.
One of the interesting things about J/XFS and remote device access (based on RMI) is that it is just matter of configuration.
You need to configure a J/XFS repository in order to handle a remote device (basically set 'remoteAccess' to true).
Then accessing these devices from the programming point of view is just the same as they were local devices.
Architecture is explained here: ftp://ftp.cencenelec.eu/CWA/CEN/WS-J-XFS/cwa14923/cwa14923-01-2004-May.pdf
Details, when programming may differ depending on the J/XFS implementation you are using.
Trying to answer your question below:
Whenever you want to access a device remotely in J/XFS, RMI is used. You need to make the following setup:
On a server (should be accessible) you need to start a JxfsServer. The JxfsServer will use a Read.repository
whith all the ATM's and devices configured on them as workstations, with the right IP addresses.
On the ATM, you need to install:
J/XFS libs
J/XFS device services for the devices on the ATM
Setup the DSstarter:
Will use the SpecificDeviceManagerRMI connecting to the JxfsServer you started before.
On your server (cloud) wherever you are going to use the J/XFS client you can get the remote controls by performing
the J/XFS initialization as follows:
jxfsDM_ = JxfsDeviceManager.getReference();
jxfsDM_.initialize("com.jxfs.forum.communication.rmi.SpecificDeviceManagerRMI,<atmWorkstation>,AppTest,2006;<jxfsserverhostname>,");
Then you can get the remote device controls with getDevice(...), and start using them as if they were local devices.
Please, note that handling RMI ports can be tricky, specially in a secured environment as ATM network. Make sure all the ports you need are open.
So I was wondering if it's possible to run a MQTT broker on the Google App Engine platform?
Couldn't find any information about it (or maybe I might be using the wrong keywords).
I've got my GAE running on Java so I'd like to go into direction of running the MQTT broker on GAE using a backend.
EDIT:
Did some further research and it seems Moquette is running on Java. Does someone have experience running Moquette on the GAE?
EDIT2:
Ok, it seems the examples of Moquette are running using an OSGi container, which is unavailble in GAE. Looking for a script to start this server on GAE.
MQTT is protocol on top of TCP. In order to run MQTT server, one needs to be able to open a listening socket. Those are still not supported on normal AppEngine instances.
Note: GAE backends have been replaced: now you just have automatic scaled (aka frontend) instances and manual scaled (aka backend) instances.
Back to your problem: Managed VMs have most of the benefits of GAE (access to services), but run a full JVM, which allows listening sockets.
An alternative to Moquette would also be the HiveMQ broker, it also runs on Java and can be easily installed. All the documentation is available here.
We haven't tested it on GAE yet, but if you have any problems running it, you could ask in the support forum.
Update: If Peter Knego is right, then HiveMQ or any other MQTT broker won't work on GAE.
Full disclose: I'm working for the company, who develops HiveMQ.
Cheers,
Christian
#Peter Knego is definitely right, and all i would add to his answer is that,
If you manage to configure you application to use a custom Runtime on the Managed Vms of Appengine and Compute Engine,
then you will be able to run you MQTT brooker perfectly sound and well.
As long as you define a fire wall to allow a tcp connection at the port which your broker is listening from.
By default the ports are blocked for security reasons.
I would like to manage a connection between 2 applications, they will run on diffrent phones.
The purpose doesn't really matters let's say that it would be some kind of a chat.
How can I create this connection between the applications? I know how to do it on pc java programs using the socket and the serverSocket classes but I guess it's diffrent in here since the phone might change his ip when he moves between networks.
So how would you do that? how would you create a connection between 2 applications/phones
Given the scenario you described in your comment, using Push Notification i.e Google Cloud Messaging (GCM) might be sufficient.
So, when program B wants update from program A, it will ask the server to push a notification (via GCM) to program A. Note that program A will not connect to the server every x time to check for updates.
Another out-of-the-box solution is to use SMS if the communication is not so frequent and messages are short. Here I mean SMS that will be processed directly by your app (given it has certain attention word) and will not go to the inbox i.e. no SMS notification on the phone
Since the two phones will, as you note, have changing IP addresses, you'll probably need to use an intermediary.
The general design pattern here would be to have a server with a fixed IP or DNS address that relays messages between your two mobile devices. The simplest implementation would be a webserver, to which each phone would connect via HTTP(S) to transmit data or poll for updates.
There are a number of backend-as-a-service platforms that provide this type of functionality pre-built, and would likely suffice for something like a chat system. Check out Cloudmine and Parse.
If you need a low-latency or near-realtime connection, you could also consider implementing your own server that uses the Android C2DM (Cloud to Device Messaging) service.
See Android's Sample Bluetooth Chat App, It will give you an idea for how it can be achieved.
Recently i developed a simple chat application in java using sockets. It was working fine. But now i want to make an application which can communicate over the Local Area Networks like IPMSG. The features will be
message sending.
file sending.
voice chat.
group chat.
encryption/decryption on demand.
These were the basic features to be included.
Now the confusion i am facing over here is
The application is an peer to peer application in which one user can do anything what other users can do.
There is no centralized server and there in no client. Every node acts as a server and client both.
So the application has to be peer to peer. But when i googled it then i am getting samples like client-server only and when i talk to my peers regarding this then also they suggest me the client-server model but there is no justification for why client-server and why not peer to peer. Am i right in this case ? Can anyone please guide me in this case because once i start development on any of these concept i cannot revert back due to time shortage. Your suggestions are most welcome.
I think the main reason a server-client relation is advised, is to make it easier for logging, or make a large chatroom for everyone (like IRC). If there is a login required, the server would also verify the login details. So without a server in between, phishing attacks would become more difficult to deal with.
I don't see why a P2P chat wouldn't work, though. If I recall correctly, Skype is doing that. I always love decentralizing. Good luck with your project. :)
You might want to check out the Zeroconf standard and packages that use it like Avahi (linux FOSS) or Bonjour (Apple & Windows open-source but not GPL). Zeroconf allows for configuration and detection of network services without user interaction or a central configuration server.
I end up using a client server model modified to support to P2P networking. When a node comes into the network it broadcasts its presence and the other nodes are continuously listening for new nodes. Each node will have their own list for the connected nodes in the network. In case of new node coming into the network they will update their own lists. I am using UDP for all most all the operations except file transfer as it needs to be in TCP.