I have been searching if it is possible to develop a multiplayer game with socket programming on android platform over WiFi but I couldn't come across with a certain answer.
As I found out, there are ServerSocket and Socket classes in android sdk.
Can I use those to establish communication between 2 devices, over WiFi?
Also if I can make 2 devices connected somehow, how should I combine this with my game architecture?
Any advice will greatly appreciated. This is my first try on Android and Socket Programming. I heard about Skiller, WiFi Direct and some other stuffs but It has to be done with Sockets.
I am actually from Skiller and I will try to address at least some of your points:
Why do you need sockets for your game? It will help a lot if you will explain what exactly you are trying to achieve. Maybe there are other, less complicated, ways you can achieve the same thing. And integrating the communication solution with your game logic relies directly on that.
Directly connecting two devices, whether they are connected using wifi or 3G is a very complicated task. In order to do so you need to know the IPs of the devices and it varies from difficult (wifi - depends on the wifi you are connecting to) to almost impossible (3g - you can not see the ip of the device behind operators proxy) unless you implement couple different techniques or use intermediate servers to do that job. These solutions of course will cost you because of a hardware resources and the most important time resource. From my experience in that field I strongly recommend to use existing solutions if it matches your needs (and I am really trying to be objective ;))
Hope it helps to further investigate what you need for your game. If you want to check out Skiller SDK you are more than welcome to do that in our wiki: http://wiki.skiller-games.com/ or send an email to developers#skiller-games.com
Michael
Related
I'm trying to make a simple chat app on Android for learning purposes. I would like it to have the following features: Different "rooms" which people can create/join. Working of Bluetooth/WiFi Direct (Preferably WiFi direct). Passwords on rooms.
I'm having a number of problems however. I don't fully understand WiFi Direct. I've read and re-read the guides and references on developer.android.com and I've asked multiple times on #android-dev on freenode to no avail. Would someone be able to explain if what I outlined is even possible using WiFi direct and if not, what should I use?
TL;DR: Explain WiFi Direct's network structure and capabilities and provide resources for learning if possible.
It is possible using WiFi direct.A room can be considerd a P2P group(1 group owner+ one or more clients) .The person who starts a "room" becomes a P2P group owner and whoever wants to join a group has to undergo the authenticatio process.A client can directly communicate with owner but to communicate with other clients in the group it has to go through the owner.
For detailed understanding of wifi direct better go through the wifi p2p tecnical specification v1.2 which can be found in WiFi alliance website under published specs. Or for a overview Click [here] (http://enjambre.it.uc3m.es/~agsaaved/papers/2012_camps_wircommag.pdf).
It is possible in theory but currently the framework of wifi-direct is too unreliable..
I have tried it and the connection is very unreliable ,it breaks abruptly for no reason. Also beyond 3 devices it doesn't scale very well ,though i tested it on tablets having very less processing power (maybe on good phones it might allow one or two more connections).
So i would recommend you use wifi for communication . it would be the best suited for your needs and easier to work with as well
I'm developping a video game on both pc and android using libgdx.
And i would like to connect them by Wifi or Bluetooth on a local network. The idea is to play in p2p, establishing this connection easily.
Please anyone can give help or source code for that, knowing that the connections can be : android/android but also PC/PC (since libgdx allows that)? I have absolutely no idea.
Thanks
Well because libgdx doesn't have good networking support you can write your own, but i've found that Kryonet is very good. It takes a lot of the hassle out of writing the network layer of your application and I've used it to connect mobile and desktop with no problems. Definably worth a quick view. It also has some good examples to get your up and running with a network game too.
I've also found this article by valve very usefull.
Networking is somewhat beyond the scope of Libgdx. There is some basic support for HTTP GET/POST/PUT, but it implies you already have a DNS name or IP address to connect to, which usually implies you have a relatively fixed "server" to connect to (not an arbitrary peer). Peer-to-peer networking is definitely beyond the scope of Libgdx.
On the upside, since Android and Desktop networking are already pretty close, you can use most any pure-Java networking infrastructure that supports peer-to-peer. See other Stack Overflow questions like: Peer-to-Peer communication options I think you'll discover that the really hard part of peer-to-peer networking is "discovery" (that is figuring the address of the peer you care about).
There is little to no documentation on it, but LibGDX does have a platform independant (Android, Desktop, iOS and GWT) socket class.
I'd link you to an example of it's usage, but as I stated; there's no written documentation/example.
However, I can give you this link as a good starting point.
http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/Net.html
libgdx-net looks good. https://github.com/pepedeab/libGDX-Net
Ive not yet tested it myself though.
How can I play bluetooth chess with my iPhone and my friend's Android device? Api? (Probably duplicate of other questions)
ZeroConf a.k.a. Bonjour is a fine way to discover other devices providing services, and it's limited to the local network. One of its best features is that it doesn't require any prior knowledge or setup -- it's mission is service discovery.
Why not just use a web service? It'd be easier than doing bluetooth discovery and pairing or wifi-server client stuff (trust me, at least on the latter). It's the easiest way to make everything relatively network (ie 3g/4g/wifi) independent. You just have a simple protocol your app follows, and you can play with all players everywhere, no discovery needed. Probably less battery drain than bluetooth too.
Bonjour is great for discovering stuff (ie other players) on the same network. The problem with bonjour is you usually need to be on the same wifi network (though not necessarily, but don't ask me how the hell this works, but it can be done apparently). You'd also in theory need to apply for an bonjour/mdns id, though this is pretty easy.
Here's a similar question.
The Following Link Provides a Book Named "Beginning IOS Game Center and Game Kit: For IPhone, IPad and IPod Touch" Hope this Will Help.Best of luck.
http://books.google.co.in/books?id=C9xVXg3w-LcC&pg=PA2&lpg=PA2&dq=gamekit+for+networking+in+ios&source=bl&ots=tcO-uKk5ZC&sig=g4ft4nUBep40NCHj9skyLK6fWJQ&hl=en&sa=X&ei=hPWzT6_TGY2zrAe-jMmADA&sqi=2&ved=0CGIQ6AEwBw#v=onepage&q=gamekit%20for%20networking%20in%20ios&f=false
I am currently developing an android application which requires two devices to communicate over TCP (I can't silently loose packets so UDP is out). I need the communication to be as fast as possible (i.e. I have a low acceptable latency threshold) but the connections will be short lived (likely less than 2min). The phones will connect, do their thing, then close the connection.
I have done quite a bit of research regarding NAT hole punching, but there does not seem to be a reliable tcp hole punching method implemented for java and android. Thus, it seems my only option is to develop a server application which will "proxy" the tcp communications between the two devices.
I have two questions:
1) I don't want to re-invent the wheel: is there a simple tcp proxy already written I can use? (note: not an http proxy of any sort - because I need low latency I am simply looking to pass a very small payload between the two tcp socket connections on the devices). The sole purpose of the server is to avoid NAT issues.
2) If not, does anyone have experience with this sort of thing and what would they recommend? I have played around with the idea of Java NIO or perhaps a server that creates a new thread for each connection (the problem being how to link the appropriate "client" threads to pass the information back and forth). Or is Java even the best language to use for the server end?
I have read some recommendations of using XMPP via google's chat services (see here) but I don't want the overhead of XMPP.
Any direction or suggestions would be greatly appreciated.
As for the direct answers to your questions:
1) Not a good one I have found, it really depends on what's available on your server. I did write one some time ago in PHP and was VERY quick and simple and will work with most servers. I used this as a guide http://devzone.zend.com/209/writing-socket-servers-in-php/
If you can run a compiled C++ binary you could look here, it was an alternative we considered:
http://tcpproxy.codeplex.com/
2) see answer to 1 for PHP option, I don't have experience in writing from scratch in Java.
As an aside on NAT traversal... I have been investigating the same NAT issue for project I am working on and I found 2 options that would require the NDK but could work well for NAT traversal on Android.
pjnath (GPL):
www.pjsip.org/pjnath/docs/html
code.google.com/p/csipsimple/source/browse/trunk/pjsip_android/?r=201
libnice(LGPL):
nice.freedesktop.org/wiki/
I'm trying to make an app on an Android device that will control an application on an iPad or Android tablet. (I'm testing with an Samsung Galaxy S2 and an iPad 2).
The application is pretty simple for now. When one selects a colour on the Android mobile, that colour displays on the tablet device.
The question is, how to connect the two devices. Just now I've verified that I can pair the two devices using Bluetooth. Also, the Samsung has a "Kies" Wifi Direct feature (which I don't understand fully), that allows the iPad to connect to the Galaxy as a wifi hotspot.
The connections are there, but I don't know if either protocol can be used to actually get the apps to talk to each other to get the control I'm looking for.
Should I be using Bluetooth, Wifi, or something else?
And in whichever case, how?
My opinion is that you should not stick so much around the physical medium used for connectivity either is WiFi or Bluetooth. You should abstract this aspect, in both cases you will be using sockets (I'm speaking about Android), if it's Bluetooth you will be using Bluetooth Sockets, if it's WiFi: TCP sockets. You could have a intermediate layer that abstracts the type of connection and through a factory to use either Bluetooth or TCP.
Bluetooth - http://developer.android.com/guide/topics/wireless/bluetooth.html
For WiFi you should study if P2P would help.
You will need two applications:
- one on the tablet - the server which listens for commands from the client (change color, do this or this)
- second on the smartphone - the client which sends commands.
I've built a few apps that do exactly that between iPhone and iPad. But the principle is the same. I used Bonjour networking. It's just a fancy name for ZeroConfig networking between devices. It's written originally by Apple but it's open source so there should be Android support out there for it too. Really simple and easy to work with.
If you already have a working connection then you already have the first half of your answer, that said you should really consider implementing a solution that uses a variety of connection types, WIFI, Bluetooth, etc.. The question I think you are really asking is how to pass data and messages between the apps once you have the connection.
There are a lot of ways to accomplish this. You could implement your own lightweight message passing system. If you haven't done this before it is more complicated than it originally seems, especially as you would be required to implement the system for each OS you end up using.
Should I be using Bluetooth, Wifi, or something else?
It depends on what situations you want your program to work in.
Bluetooth can provide a direct connection between your devices. A potential issue with bluetooth is that it has a limited range. If you're devices need to be far away from each other, you may want to go with wifi. Otherwise, bluetooth could work great.
If both devices are connected to the internet, you can make them talk to each other through there. The advantage of this approach is that it doesn't matter how far apart your devices are as long as they're both online. A disadvantage is that you'll have to figure out how to find the tablet's ip address before you can talk to it. This is actually a HUGE disadvantage because it can be quite problematic if both of your devices are not on the same wifi. You could have the user type in the destination ip address, but you'll have problems getting it to work if the user is behind a router (which will almost always be the case). The point is, it gets hairy.
If both of your devices are on the same wifi, you can use ZeroConf AKA bonjour (like Dancreek said) to figure out what ip address you need to send info to. I've previously used a library called jmdns (easy to find with google) to implement zero configuration networking. It's good because the user doesn't have to worry about ip addresses... it's intuitive for the user.
And in whichever case, how?
Networking is a pretty big topic, so I can't expand on this question to much. Short answer is, it depends on what method you choose. Search for some tutorials and start by getting one of your devices to send something as simple as an int to the other.