Realtime P2P communication between mobile devices - android

I am building a mobile device that needs to send realtime information to other devices. I have considered XMPP but I do not have a server, so the communication must be only between the devices.
Is there a way to communicate using XMPP between mobile devices without a server (Or using the mobile devices as servers)?
Is Sockets a good idea ? i.e. Having a ServerSocket and client Socket and communicating this way.
Is there a smarter way? I have heard of jWebSocket but I dont really know how it works or if it's worth it.
EDIT
The process is as follows:
I'm using Parse as a server/backend http://parse.com
When the user runs the app, a user list is retrieved from the parse server
The user then has (Could have) the ip of other clients and then attempt to communicate with them.
Problems
1. Parse does not support a XMPP server or other type of servers

You might look at using an IRC client library like http://jerklib.wikia.com/wiki/JerkLib_Wiki. This way you can use a public IRC server to communicate with your other devices...
I've not used it, but I did bookmark it for further reading because I thought it a novel concept ...
I hope it helps...

Related

best way to connect android app with desktop app?

I want to develop a system in which data is being shared between DESKTOP app and Android app.
After searching I have found that I need a server in between them. But I can't figure out what the server is? How do I create it? And how will it help me connect my two platform devices?
Desktop App will receive data from android app. And manage data. It will also be used to send notifications/messages to android apps.
Android App will be used to input data and send it to desktop app. It will receive updates/notifications from desktop app.
Now how do I connect these two? I basically need a common database for real-time data sharing and notifications.
Edit: I am building the desktop app using C# and android app using Java.
Edit2: Maybe I can host the database on CPANEL or 000webhost using PHP. And then connect it with both android and C#. Is this the correct way to do it? Is it possible to connect it with C#? I know it can be connected with Android, not sure about C#.
You don't necessarily need a database. You need a common network protocol between two applications.
All network communication is done via sockets. You need a library that allows you send data over sockets. For example, here's an Android guide that is about sockets.
A socket binds to a specific port of a computer, essentially making it a "server". Much like how web servers all expose port 80, and communicate over a protocol called HTTP. Which is important because it is up to you to decide what protocol your applications communicate between each other, because the socket just sends bytes - it doesn't care what you send or how, as long as it travels to a port on a particular server. It also won't parse the data for you, that's up to your application to handle. For example, how would your desktop app know the Android device sent it a text message, or some image to be displayed, or an address to show a map?
All in all, your reason for wanting a desktop application rather than a web application is not entirely clear. Parsing only the body of HTTP payloads from different HTTP paths that are mapped to different methods (which is typically referred to as a REST API) is much simpler than building your own protocol. You might as well build a desktop GUI over top of a web server.
Making the desktop app send updates back to your mobile application is basically impossible using a bi-directional socket architecture. Your Android should not be running an open server socket continuously just for your application, mostly because battery drain, but because its network address is subject to change frequently, and you therefore additionally need a registration server from which your device would reconnect to. Such a service exists as Firebase Cloud Messaging, which is a rebranding of the GCM technology made by Google, and it can be used to send push notifications to devices, but only with small data payloads.
See here about what activities occur on an Android device for notifications. How does push notification technology work on Android?
Back to the question about databases. Suggesting one to use is too broad. And you only need one of those if you want to store and/or query or join datasets. The same computer running the desktop app can install and run whatever flavor of database you prefer, whether it's a relational database or noSQL database, entirely up to you. The only realtime databases I know of are RethinkDB and Firebase.
You could also just hold a SQLite file which is as good as a small scale database (even the SQLite documentation recommends it for low traffic web sites).
Firebase supports web interface, so you can develop html code and integrate in desktop app, something like web integration in windows form application

Sending data from android app to remote publicy accessible machine

I'm planning to write up an android App that will collect some data from a smartphone and periodically send the data to some publicly accessible machine (i.e., the machine has a public IP address). What is the best approach to doing this? Is there any good sample code or skeleton available online?
At this point the communication is one way, i.e., from smartphone to external machine.
HTTP is the ideal solution for an application like this. Run a web server on the external machine and POST data from the app to the server.
Info on how to do this from Android can be found here: How to send a data to a web server from Android.
As for the web server side of things, there are a ton of different solutions available. It all depends on your level of knowledge, what languages you're familiar with, and what you intend to do with the data once it arrives.
CGI is the classic web server tool for handling POST requests, but there are better techniques now. For example, the Java Servlet API if you like Java, WSGI if you like Python, PHP is a common server side language also.

GCM Server/Sender Setup for Device-to-Device Communication in Android

I've been reading through the GCM developer page and none of it seems too complicated. However, from an overview standpoint, I'm confused on exactly what I want. I have an application on one device that will send some information to another Android device, which then does something with that information. It's just a pair of doubles.
I've never had any experience doing much web communication aside from simple website/router stuff, so I realize this is a very inexperienced question-- but when I set up GCM on my two devices, what device is acting as the "server" and which as the "client"? Are both clients and Google is the server?
Thanks for any help.
I think you Want to Make Two side communication. you can Do One think that Save your RegistrationID of phone on to the Server. what ever the Data you want to communicate you should save it First to server. and whenever the Notification sent by the Server it will give information to perticular Client with using Registration ID.
Both android devices are considered clients. The clients will communicate with a backend server which can be implemented in a variety of ways. The sample that Google provides uses a standard web app written for the Java App Engine. You can find the example here:
Setting Up the Server
You can also write the server using ASP.NET, PHP, etc. What I typically will have on the backend is also a SQL database to manage the devices that are registered with my application. Each device (client) is given a unique ID from Google which the server will use to communicate. The server uses this ID because the messages it will send is not directly to the client but to GCM service. So in essence the Google GCM is a server to your backend server which is a client to GCM.
Hopefully this answers your questions regarding client/server communication. Please look at Googles demo for detailed implementation. Good luck!

Android app, open connection to to mobile devices

what is the best way to create a two way constant communication between a server and an android app?
When I say constant communication, I mean client asking server for data or server constantly pushing data to clients.
From what I saw, I can't use websockets since they are designer for server/browser setups. Is that right? If so, what is the alternative?
Is there free frameworks to work with this in Android?
What I am trying to do is an application that works like a chatting but for multiple people. So they all will get in one "room or channel" on their devices, and then interact with each other, in a way handdled by the server.
Thanks!
As far as I know , one possible way is using a web service where the client can connect to the server , if the web service is RESTFul there are many libraries to access it , one of them is the apache HTTPClient , for the server pushing the only way I know is C2DM for pushing data to clients.
For continuously-open data connection, you may use Sockets. But you should also consider the fact that an always-open connection will drain your battery quickly too. For more details, read this and this
You may want to look at AutobahnAndroid:
https://github.com/tavendo/AutobahnAndroid
which provides native Android/Java WebSocket client framework (plus WAMP = PubSub/RPC over WebSocket .. http://wamp.ws).
This is fully interoperable with WebSocket servers that server browser clients.
The AutobahnXX libraries (where XX = Python, JS, Android) are Open-Source (Apache 2.0). We (Tavendo) are offering a commercial virtual appliance based on Autobahn: http://autobahn.ws
Disclaimer: I am author of Autobahn and work for Tavendo.
But keeping the connection running on the background on iOS and Android devices does drain the battery, for people who have this issue, I suggest using push notifications when the app is not on the foreground.
From what I saw, I can't use websockets since they are designer for
server/browser setups. Is that right? If so, what is the alternative?
Websocket is an IETF/W3C protocol, so it is not confined to a specific client platform. You can use Android websocket to get a two-way communication between Android and server side. For Android websocket client, I recommend using AndroidAsync. It has all websocket API that you need to establish the communication link and exchange data between Android and the server.

What's the best way to implement an application server for smartphone app?

I intend to write a multi platform smartphone app (currently only I-phone and android).
Which has to send and recieve information from a web server I intend to create.
The web server will do all the algorithms, and handles also DB connection.
My question, is how is this best accomplished, which kind of web-server technology fit best the scenario, and supports connections from various devices.
Basically, I thought about implementing a simple TCP/IP protocol, making the app (on the phone) the client, and server on the web on the other side. however, I want to deploy the application to an application server (maybe google app, JBOSS, etc.) and I don't want to be stopped by various firewalls.
does anyone has an idea ?
edit: few things are certain, the application server will be written in java, and db will be mysql.
This is a very broad question and any suggestion about which backend technology to use will depend on your language preferences, your other requirements, etc.
For starters, I'd suggest JSON over HTTP as a transport mechanism: it's easy to parse on both client and server-side, and it's directly usable in Javascript should the need arise. XML is another choice, but it can be annoying to parse.
JSON-over-HTTP (or XML) will be completely device agnostic and won't have the firewall/proxy problems you'll run into trying to do a custom-implemented TCP-based protocol.
For the backend, may folks use MySQL or Postgres for their database, and connect to it from Java, C#, Ruby, PHP, or other server-side languages. Use what you're comfortable with or what you want to learn next.
Why not write the server-side as a regular web application - in whatever technology you like (php, asp.net, java)? This way you can deploy the app on any web server and your client apps on the phones would simply establish a connection to an HTTP server. Normally, firewalls would not be a problem in such situation.
I have used this setup for my apps (both android and iphone) - connecting to a web server app written in php with postgres back-end.

Categories

Resources