For mobile development i woud like to move something on the screen on a mobile device and on another mobile device you see the same object moving.
What would be my best option to use to exchange this data? I thought about firebase but the problem is you move the image alot of times so you easily get to the 50000 limit within an hour. also the fact that saving an position is abit odd to do in a database.
My second option would be using netty framework. I thought about using their socketstream option. My question about this is, my school stresses the use of an api between data exchange but is that also possible here? or is that more for webdevelopment?
In summery, What would be the best option to use for data exchange if you need to send alot of small request. If you sockets/nio framework is it normal to put an api between the client and server?
I thought about firebase but the problem is...
You don’t need a database because you don’t want to save the object’s position. This data is not valuable to you (right?).
You need to pass data from one device to the other to see the object moving. This can be done by establishing a network between these two devices. This can be done using sockets.
If you sockets/nio framework is it normal to put an api between the
client and server?
If this API use sockets under the hood to simplify a client/server implementation for example then it’s not a good idea to use sockets. They’ve already being used by the API.
On the other hand if the API does need socket implementation from your part to be used correctly, like the android Bluetooth API, then yes it’s normal.
Your use case
You can do this by connecting the two devices on the same network and transmit freely any data you like.
If this network doesn’t need to be the Internet then you may want to transmit data over
Bluetooth
WiFi p2p
or your local WiFi using NSD
For these and more see Android Connectivity.
Related
I am trying to emulate this app - Wifi Direct sensors (https://play.google.com/store/apps/details?id=esnetlab.apps.android.wifidirectsensors)
I have gone through the demo of wifi-direct from android samples.
I am able to get sensors data on a individual device, but i need to get them from the peers in a wifi-direct group.
So I wanted to know if someone could suggest on how to go about the design/process of getting the sensors data from 'remote sensors' on one device (as shown in the screenshot of that app).
There are basically three components you are going to need...
If you're going to want to plot the results, need a plotting library like Androidplot.
You're going to need to establish a Wi-Fi direct connection between the devices. There is sample code for this in the android SDK, but it isn't in the newest SDKs, I think it's in levels 14 to 18, or something like that. In the samples, they show you how to open a socket connection and send a file. You just need to leave the socket connections open.
The sensor event class is not serializable, and I think its constructor is either protected or private. This makes it difficult to send over a socket since it is difficult to reconstruct the sensor event on the peer. A library like Gson might help with this, but an easier way would be to pick a subclass of information that is important to you and to just send that info.
What you want to do will be a lot of work.
I'm making an app using bluetooth, and I realized it'd be pretty neat to exchange data between 2 running devices via bluetooth.
However, as far as I know most Bluetooth devices use a traditional server/client architecture, so the information exchange is one sided, ie, client requests data from server, server sends it, but not the other way around.
To get around this problem, I tried to make each device have a server instance as well as a client instance, so that the client can hook up the the server in the other device. However this does not seem efficient as this requires 2 channels of communication instead of one.
Then I tried going to Bluetooth website, and they suggested "role switching", that is, when server wants some data from client, server makes itself a client and client becomes a server, so the role is reversed. I don't quite like it either, because why can't 2 devices play the same role and exchange data at the same time? What kind of connection is this called then?
I have not had experience in networking so my question might seem naive, but I'd like to have someone point out the answer, or tell me what information/which chapters of textbook I'm missing so I can wiki it.
Role switching affects the underlying Bluetooth topology: which device is master in the piconet. That can have implications for the quality of your connection, but it does not directly affect the direction of communication in the way that you are imagining: it is at a much lower level.
Yes, in Android Bluetooth comm is done using sockets abstraction and the setup of the socket connection is done in a client-server manner. But once the socket is connected both sides have a BluetoothSocket instance and I'm pretty sure that both sides can get an output stream and initiate communication. What makes you think otherwise?
I'm totally new to network sockets so any help is appreciated.
I'd like to know how to setup a network socket on an Android device and use it to pass data generated by an App to another App on the device.
This is because the App receiving the Data will at some point have to be able to receive data from an external source, so I'd like to build in the basics of this before I get to that point.
Any example code etc. would be great and I'll edit my question as I go if required.
I don't think using sockets can solve your problem. Only one app can be active at a given time, and the connection won't work. Unless you create some sort of service, but this approach seems wrong.
I believe you have 2 basic options in front of you:
A server that both apps communicate with.
Writing information to the disk in a globally readable place.
The server option is better IMO.
Hi all I was wondering what options do we have to exchange data between two different android devices?
For example, User-A and User-B both installs my app. I would like User-A to send data (possibly just a simple message or user-A's location info) to User-B.
The functionality I would need is similar to the functionality that WhatsApp has. However unlike WhatsApp, I do not have a server and I was wondering if we could do data exchange between two different android devices without a server?
I was thinking we build it atop SMS or something.
Options for exchanging information between devices are the following:
Bluetooth - this would be between two devices in the near vicinity
TCP/UDP IP connection - this would be using TCP to open a socket directly to another server socket. That could be hosted on the phone or a shared server. There are pros and cons to both.
The pros of bluetooth would be no need for a central server. The big downside is this means you can only exchange data between two people standing within 20 meter range. The other downside is you have to pair the devices which not everyone finds easiest.
You can use TCP/IP connections to exchange data just like any client-server program you write on a traditional computer. This could be used no matter if your phone is using 3G/4G/WIFI/EDGE or future radio protocols. The problem is the IP address of the phone might not be globally reachable. The IP address of the phone might be a non-routable like a private IP. They might be behind a firewall or NAT address.
This is where a central server is probably needed to either exchange IP addresses for users, or serve as a common location for clients behind infrastructure that could block. This is where protocols like SWIFT come in handy for jumping firewalls. Even with things like P2P you still run into these types of issues with non-accessible devices, and tricks like this have to be used to crawl around them. Unfortunately, that means you probably need a central server even with the P2P model.
Without an external server to keep a list of all connected clients, you would need to implement communication in a P2P fashion. Depending on the needs of your app, you could have the user type in the IP address/email/phone number of the other user they want to exchange data with.
If you wish to use a server approach, you can sign up for Google's App Engine which has good Eclipse integration as well as a plugin to easily interface with an Android app. This would give you an infrastructure option without initially (or maybe never depending on how high you scale) having to put down any money.
Google gave a good IO talk showing an example of a web app that can easily communicate with an Android app. You could extend this to do what you are looking to do.
Does anyone know how to implement communication between 2 android devices over the internet without using App Engine? For example, I have 2 Android devices, and I want to send a stream of data from one to the second one over the internet. I would like to know, if someone could give me an idea, how could I identify the second device (or how to create a communication channel between two devices ), so I could initiate the transfer (this is not possible using IP addresses ?).If i were to have my own server, which is the best way to go to accomplish this? If someone could point me to some useful resources I would be grateful.I have some background on android programming.
One way I was thinking to accomplish this was to write an android application, and when the user enters it, it will start a service. This service will then listen for network events and registers on my own server with the username and the IP address of the device as available.When another device wants to send data, it will connect to the server, search for the target device (by username key), gets the IP address and sends the data. Could this work, or does anybody have other suggestions?
One way I thought about doing this is making
(excuse the spelling mistakes if any)
It would help if we knew what kind of data you were trying to transfer.
For small bits of information, like notifications, events, and the like, I would suggest doing an HTTP POST to a server that has C2DM capabilities, and using the server as an intermediary.
For larger data, the only way I can think of to do it is to set up a SyncAdapter, then upload the information to the server. The delay will be a bit longer, but you'll reliably get the information downloaded from the server to the phone. So less of a communication API and more of a dropbox for phones.
I haven't done much with NFC, but that may be something you want to look into.