问题
I want to send notifications to some devices connected to my local network. First alternative was GCM but this implies sending a message to Google server and then Google server sends the message to devices. What if currently my local network is not providing internet?
If there is no such alternative like this, is there a way to send a message through a TCP package directly to the device?
回答1:
You should take a look at MQTT. There is also a Java library that is compatible with Android; the Eclipse Paho Client. In very simplistic terms, MQTT an asynchronous publish/subscribe mechanism that is well suited for what you want. It runs on top of TCP/IP.. You will need to use a MQTT broker on the server side (i.e. mosquitto (mosquitto.org) or RSMB (Really Small Message Broaker), etc)
If you are interested, I created a simple project that allows you to connect to a Raspberry Pi and turn the lights of your house on and off using and Android device. Here is the git
来源:https://stackoverflow.com/questions/17504761/gcm-alternative-for-local-networks-or-sending-messages-to-device-ip