How to comunicate two androids devices - android

I'm developing an online pong game in which two players could play between them.
I though that for it, players will have to conect to a server and it will tell the players who is online to play. Also the server will save rankings and other stuff.
But for the play, at first I though to use the server for the match too (sending coordinates, etc), but I think that is not the best design because it is really slow.
So I'm thinking that android devices have to can comunicate between them, isn't it? Any idea? They have an ID...
If they can... the server could send the ID of the opponent and with that, the match will start comunicating the stuff between the mobile devices and not with the server.
Need some help pls!

You can set up a direct connection between the phones, definitely. Make it so the server coordinates the matchup, sends each player the other player's data (IP and such).
You'll have to use/develop a server/client system between the players. One of the players will act as a server and the other will connect directly to it. Make sure they can properly identify each other. You can make the central server decide which player will act as the match server. A simple UDP connection over the network will do the trick.
This scheme will save you on bandwidth for the central server and probably be faster for the players. However, it IS one more subsystem you have to code.
Make sure you properly weigh those factors and remember that a fast deployment is sometimes better than no deployment at all. (SOMETIMES)

Related

Server software for handling multiple mp3/ogg streams

I'm looking for advice regarding an aspect of a project I'm working on.
I'm developing a demo android app for a not-for-profit that specialises in services for the vision impaired. The plan is, among other things, the app will enable users to stream this organization's specialised audiobooks.
For the sake of demo'ing/development I need to establish some sort of server which will, pending a request from a device running the app:
directly transfer certain xml/html index files to the android phone (no streaming necessary)
stream .ogg and .mp3 audio files to the device
serve more than one client device at a time
start a stream from a specific point within an mp3/ogg file, pending a request from the phone app
I've had a look at Icecast as an mp3/ogg streaming solution, but my knowledge of servers is a bit limited (I've only ever done some basic work in Flask). Would I need to run this in tandem with something that can generically serve files / handle requests?
I'm basically just looking for a good solution/tool to implement this is. The server side doesn't need to be completely fleshed out, just fit the bill above, as my focus is developing the phone app side for now. For the sake of a demo, something straightforward / well documented would suit best.
You don't need a special server for this. Any HTTP server that supports range requests will be fine. This includes Nginx, Apache, etc. There is no need to spoon-feed clients media data from the server. This streaming and buffering aspect is handled automatically on the client, through TCP window size and outright closing the connection and connecting again later as-needed.
Icecast is meant for radio-style streams where everyone listening hears the same thing at roughly the same time. Since that's not an aspect you want, stick to any normal HTTP server.

how to synchronize display of multiple android devices?

I was thinking of using multiple Android devices (e.g. Nexus 7 tablets) to build a photo / video wall and I'm wondering a) whether it is possible and b) how to synchronize the display of all these devices. Google showed off its Chrome racer experiment so clearly it is possible to synchronize displays across many devices.
So here are my questions:
what technology should I use to synchronize the displays? Android? Chrome? Please point me to existing code if possible.
what's the minimum lag between devices that could be achieved in such a setup?
can video and sound playback also be started simultaneously on multiple devices (think video wall)?
what kind of architecture should be considered for such a project? Centralized server that sends out commands? Should devices talk to each other?
I'm very curious about suggestions!
EDIT:
blinkendroid is the only app I've found so far that might do the job. Pros? Cons? Alternatives?
Technically the screen isn't shared, the games state is shared and the phones all render the state as they understand it.
Just a bit of background about Chrome Racer. We have a case-study on here, but it doesn't fully cover the question you are asking.
The primary technology used for communication in Racer is WebSockets. WebSockets allow one client to push and receive messages from a server in near-realtime.
Racer starts a session for a game by giving it a unique ID and holds open a Web Socket to the user. Anyone who subsequently joins a game is told to use the Same ID and the server creates a Web Socket to them as well. Now the server knows all the participants.
When a game starts a message is broadcast to all the participants asking them get ready to start, during this phase the server is working out how long it takes to round trip messages to all the clients. It is doing this so that it can work out any latency between devices and thus attempt to compensate for the latency on the slower clients.
Now the server knows about the clients the game can start properly. As the users are playing their game their commands are being pushed to the server over the web socket. The server the relays this message out to all the connected clients (like a satellite does) and it does this same thing for every single user that is connected to the session. This is how the games state is shared.
As each client receives the commands that are broadcast to it from the server it updates its internal representation of the game and renders that to the screen.
And that is about it.
Actually, we wanted to use WebRTC Data Channel because it can reduce the number of hops that data has to make to reach the client. In our solution today a client pings the server and the server relays the message (2 hops), we can reduce the latency by half if we can send it directly to the other user (which is the goal of WebRTC). Unfortunately WebRTC was not ubiquitous enough to deploy this as a solution at the time.
Websockets means web. You don't need the web to sync multiple devices at the same physical place... For video/music syncing, native apps via local offline technologies like Bluetooth or WiFi sounds more reliable.

using android mobile as a server

I am developing a turn based two player android game. Is it possible to use one of the user's mobile as server rather than an external server to coordinate the game ?
I do not need much data storage. only 40 fields(text or numbers) to be stored and transmitted (for transmission , one value at a time) while the game is on. after game is over only user's current score is to be stored.
I guess to do any such thing I need to get ip of the mobile. Is it possible ?
You need more than just the IP since the IP is just an endpoint on the Internet and there is no guarantee that it is your device that answers if you talk to that IP. There is usually a local network behind that IP and you can't access devices in there with just the public IP.
The problematic part is establishing a direct connection which is (usually) not possible on the Internet unless you are in control over the Internet connectivity (router etc) and can setup port forwardings / firewall rules / whatever blocks direct connections. If you have no access - for example because you use 3G where the "router" is at your provider's datacenter - you will need at least a server to do things like hole punching.
Also a server used to find other's games (and IPs) would be a good idea.
You can however do all that if both devices are on the same WiFi and they can see each other directly.
I am from Skiller and I think we have exactly what you need.
#zapl is right, if you want your players to connect to your games using 3G or WIFI connection the best solution will be intermediate server that makes it possible to exchange data between the players. Setting up, hosting and scaling such a server may be very expensive and time consuming thing. We provide FREE SDK tools, using which you will be able to set up your turn based two player game in no time. We are handling all the server side maintenance so you could just implement the game logic and fire your game to the market asap.
Download the SDK from www.skiller-games.com and tell me what you think.
If you have any questions write us here or to developers#skiller-games.com

How to send data from one android device to another?

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.

How to implement a communication channel between two android devices over the internet

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.

Categories

Resources