Is it possible to push data from the server to the client (phone, computer) without OS integration - networking

is there a way for a server to push some data to a client, wirelessly and seamlessly, which may be Windows(Phone), iPhone, Mac, or Android device, without any OS integration?
If so, what's the best design pattern to do this, and what are the best technologies to go about this?

Push technology is simply a methodology of the server initiating the transfer of data, rather than the client asking the server for it.
Apple makes push technology relatively easy to use by providing such functionality built-in on the OS. As well as Android through the Google Cloud Messaging for Android. Windows, however, does not.
Apple push notifications and Google's messaging for Android is seemingly magical and/or functionality that the OS needs to handle; however, this isn't necessarily the case. The advantage of having it "integrated" in the OS, is the same as having a framework handle the functionality for you.
Speaking in technical terms, push technology is a long-lived connection from the client to the server that accepts messages. These messages would be considered pushed messages, since the client did not make an individual request for them.
The main thing to keep in mind when implementing push technology yourself, is that the client is in charge of keeping that long-lived connection alive as much as possible. Because client IP addresses can change between disconnects, servers are not guaranteed that a client's address will be persistent across disconnects. Moreover, clients can be connected from behind a firewall, making it impossible for a server to reach the client.
For comparison, pull technology is the more traditional process of a client connecting to a server and requesting data.
Your best bet for Apple iOS will be using their push notification service.
For Android devices you should use the Google Cloud Messaging for Android. Alternatively, you can create your own background service to handle the messaging; here's a guide.
For Windows (desktop at least), you will have to create your own service to perform such duty. Here's an MSDN guide explaining how to create a Windows Service using Visual Studio (VB and C#). There might be frameworks already built that handle such messaging on Windows, however, I don't know of any.

Use WebSocket (with or without socket.io).
In the future, you could use WebRTC.
With Websockets, the setup is really simple. The client (a user agent, like a browser or a WebView) connects to the Websocket server, over http(s) (less problems with firewalls) and that's it. There's a bidirectional socket with an event-based API.

If by "OS integration" you mean "write special code for each platform" then the answer is no.
As you mentioned, you would like file system access, and background processing. That combination is not available in a cross-platform way at this moment.
If by "OS integration" you meant "without having to wait for apple/google/ms to provide the ability" then the answer is yes/maybe.
All the popular platforms have Push notifications and background processing support, as long as you code it the way each particular platform expects it.
But file system access will be limited to what restrictions the platform places on you. For instance in ios and win8(phone) there is no wy to write or read a file outside of your own apps private file structure. For security reasons, you cannot access the file system of other apps.
UPDATE:
The general pattern here is to release an app for every platform you want to support.
The app will register itself with its respective platform's push notification service.
You will write generic server side code to accept the data you want to push to all your client devices. Then you will invoke the respective push API's for each platform you support, causing the client devices to wake up and trigger the app that you provided to respond.
When the app opens, you get the app to contact your server and download the full data "the push notification being just the wakeup call for your app"
This way you can easily tell how which of your devices have received the data.
Each platform specific app must save the data to its own local storage and provide a way for the data to be shared via the methods supported by its respective platform.
On IOS it can be as simple as supporting the "Open In.." paradigm.
On W8Phone, you'll have to publish the data via one of the available "sharing contracts"
And so forth for every platform you want to support.
This is the general pattern at the moment. There are some caveats. On IOS, the app will nt automatically start when a push notification is received. This means your app will only download the whole of the data when the app is opened by the user.
A mobile app also cannot generally run indefinitely in the background. This means that once the app is started, you have a limited window for push notifications to be automatically processed by your app. After the allowed "background time". The app will close and any push notifications beep on the device, but wont open the app until the user taps on one of the notifications or opens the app directly.

Technically you could use XMPP Libraries, it is meant for implementing chat system (msn, gtalk, facebook chat, etc...) but this could work well as a push message system because it is opensource and well built to handle all the cases you never thought of. Also you could host your own server and send push message that way...

Why not use a webservice? In my previous project I used webservice to deliver data from mysql database. The webservice I used was nusoap. On the client side I used kSoap library for Android. Hope this helps.

if you want to receive and send real time communication between a server and client (irrespective of the device or OS), i would highly recommend you use XMPP technology because it is designed for the sort of things you're asking for.
The Extensible Messaging and Presence Protocol (XMPP) is an application profile of the Extensible Markup Language [XML] that enables the near-real-time exchange of structured yet extensible data between any two or more network entities. The core features of XMPP defined in [XMPP‑CORE] provide the building blocks for many types of near-real-time applications, which can be layered on top of the core by sending application-specific data qualified by particular XML namespaces.
http://xmpp.org/rfcs/rfc6121.html#intro - that is the latest RFC which will give you a good starting point.

Related

Control sonoff with mqtt or http?

I am wondering what is suitable for my case, using espeasy or Tasmota. I know espeasy is using http requests and Tasmota is using mqtt.
I want to control my sonoff devices by a raspberry pi that is acting as a home automation hub, and it in turn send updates and receives commands from AWSIoT platform. For interacting with AWSIoT platform, it uses mqtt.
What are the pros and cons of using either? and will it cause problems if I control several sonoff devices with http, while using mqtt for AWSIoT? or better use mqtt for all AWSIoT and sonoff?
I am not an expert on the topic but have tried a few things and got some insight for you on why to prefer MQTT over HTTP.
Security. Remember that the 'S' in IOT stands for security. Joking aside. I have not seen an option for encryption (HTTPS) of the HTTP-traffic for tasmota. (May the internet correct me if I am wrong) So choosing HTTP means your user/password (which are not a requirement but should totally be used) are transfered via URL query parameters as plain text. MQTT has built-in mechanisms for encrypting the traffic. I haven't been able to get that working in my network but I'm trying.
Flexibility/Reliability. With MQTT/Tasmota you have the ability to implement automations that do not rely on your home automation hub by having your devices publish MQTT-messages directly to each other for interaction. For example if you would like to implement an emergency off button that turns multiple devices off you do not want that to rely on your home automation server. Doing this with HTTP 'could' be done too but requires all users/passwords of all the devices to reside not only in your home automation hub but also on other single devices.
Networking. Adding new devices to your hub should be as easy as possible. In matters of HTTP your home automation hub has to know how to find your devices via IP-addresses or domain names since it has to resolve a URL. When using MQTT you just connect your tasmota devices to your broker and use their topic in the home automation hub. The devices do not even need to have a static IP or reachable domain name of mDNS name of any sort. That's in an essence what makes pub/sub for IOT so interesting in the first place.
Existing support. Before building your own home automation solution be sure to check out home assistant (my favorite) or any of the other home automation solutions if they fit your need. Do not reinvent the wheel. A tipp for home assistant: Do not use MQTT auto discovery in combination with tasmota. This is the only thing that has not worked out for me. Manually registering devices works reliably.
Hope that helps. If you still prefer HTTP checkout the app "Tasmota control".

Blocking Google Assistant during a bluetooth headset initiated voice recognition session?

I'm working on a voice recognition app that connects to custom hardware using a bluetooth handsfree profile (HFP aka headset profile) connection. The application is used to pass PCM audio data to a cloud based voice recognition server, by leveraging the Android AudioRecord class. This functionality works fine if the application initiates the SCO connection, but if the headset hardware initiates the SCO connection, by issuing the AT+BVRA HFP command to the phone, Google Assistant always hijacks the phone. Thus, my question is how can I stop this? Is there a way to programmatically tell Google Assistant to chill? I've tried many different things (AudioManager sco management, AudioRouting preferred connection, BluetoothHeadset profile class, Java Reflection & View.setAssitBlocked(true), etc...), but none of them seem able to either block Google Assistant or recapture the SCO connection. (It also seems that the handset opens up an A2DP for google assistant's audio feed). I'm hoping this is possible with a Java based solution... ?
As noted by another answer, what is likely happening is that Android is broadcasting an ACTION_VOICE_COMMAND intent, and since Google Assistant is set up to receive it, it gets priority on the connection. Your app could register for the intent and see if it gets priority on receiving it.

asp.net peer to peer chat application

I want to create an asp.net chat application and now I have two choices:
Using TCP/IP connection and creating peer to peer connection between chatters.
Using Database to store the chats text and use Ajax to create communication between the chatters.
Which one look like good solution or do have any solution?
I am assuming you intend to have your chat used in a browser, since that has different requirements than if you wanted to supply a webview to embed in a native application you are developing.
Solution 1 is not really an option. You can't establish direct p2p-connections in a browser, at least not without java/flash/plugins.
Solution 2 could work, although you don't necessarily need a database. Unless you want to save a chatlog or supply offline messages, you can simply cache recent messages on the server. When a message is more than a few minutes old, you can likely assume it to be of no interest any more. Depending on your needs ofc.
Another very interesting solution is websockets. Websockets basically provide an interface for live communication with the browser, so that clients do not need to poll for messages using ajax, but can simply hold open a connection to your server, wich supplies updates (=new messages) as they become available.
Since WebSockets are not universally supported yet (although firefox, chrome and mobile devices in general offer very good support nowadays) you should probably set up an ajax interface as a fallback for older browsers. Other than that, I think WebSockets are your best option.

What may be the issues using HTTP push for mobile devices/apps?

I have to devise a push notification plan for some mobile devices where push is not yet officially supported by C2DM / APNS / BES ,etc. MQTT was also a good option but I could not get an MQTT Client for my required platform. (Blackberry Playbook, ActionScript only)
Going back to basics, I had the options of Long Polling and streaming. Streaming using a high keep-alive value seems good to me, as the development of the mobile app (it is not a browser) and the server code are both in my control. To maintain the connection open, I just need to ping the server occasionally.
What issues I may be facing in this approach ? I understand this would constantly open an HTTP connection from the device to the server. Would the battery life of mobile device drain quickly just by persistently opening a server connection ? ...Afterall the data is not being transferred, just by keeping the connection open...right ?
You might want to consider Urban Airship or take a look at this realtime technologies guide.
If realtime really matters, I'm talking about seconds or milliseconds, then a realtime web technology using WebSockets or HTTP Streaming is your best option as they deliver updates the instant they are available. This sort of thing is best suited to the sort of application that a user is actively using during a reasonable period of time where they need instant notifications or are collaborating/chatting with others.
WebSockets are probably a better standard to be using with longer term technology considerations in mind since they are the first standard for full duplex bi-directional communication between a client (mobile, web, desktop) and server.
What platform could you not find an MQTT client for? http://mqtt.org/software lists clients in just about every language I can think of and more than I'd like to bother using. The mosquitto C client library is very portable.
For battery life, it really depends what you're doing between the keepalives...
If you app runs in a country where the network isn't in the best shape, then having all your clients keep a connection open can put strain on their infrastructure (assuming you are that popular).
Battery life is the other consideration, yes, a lot of devices aren't that efficient in keeping an idle radio/3g connection open and it drains the battery a lot faster than not having a connection open.

desktop sharing using XMPP protocole

Is it possible to use XMPP for a desktop sharing application ? is there any inconvenience ?
Technically, I guess it is possible to send the right information across. XMPP is called extensible because in a way it is. Basically XMPP allows you to send arbitrary XML to a receiver without the server needing to be configured to "accept that data". Only your clients need to be aware of it. It is not technically necessary to make/use an official extension.
What you would do would be to encapsulate VNC or RDP packets into the XML payload of the xmpp messages. Probably encoding it in a CDATA section (most efficient). The main problem that you might have is latency caused by the messaging to be routed via the server.
#dtb empathy/vino can do it on Linux with Telepathy
Yes, there is such application: http://sourceforge.net/projects/remotevnc/
There is no official protocol extension (XEP) for desktop sharing over XMPP,
and I'm not aware of any application offering desktop sharing over XMPP.
Yes it is! XMPP is an easy and extensible protocol, there are plenty of libraries to work with.
Major considerations would be:
Port and firewalls. Are any of the PC's locked down?
Application permission. Do you need to run the client app with elevated privs to access functionality, like remote control and device accesibility?
Multi-user. XMPP has group chat functionality, will that be used?
Robust. You can send offline messages.
If you don't need remote-control functionality, but just an app to share a whiteboard, text editor or such, then it should work fine.
For sharing command-line of the Linux operating system trough xmpp you can use:
pigterm.sf.net
It also supports encryption.

Resources