I need help finding the best method for networking in a multiplayer game. I want to connect to a phone and maintain the connection until the game is over, hosting the game on one of the phones. There are other threads, but none of them really explain how to connect or use the networking, only saying to use such-and-such library. Examples or links to good tutorials would be extremely helpful.
You have to options: TCP/IP sockets or Bluetooth.
For TCP/IP socket there is a good discussion on "Thinking in Enterprise Java" by Bruce Eckel, you can access the digital edition for free (see chapter 2).
Fro bluetooth there is a tutorial on the android developer website. Just be advised that peering between phones is supported only starting from android 2.0.
Related
I'm trying to create a simple glassware using GDK which wirelessly receives
data from a laptop and uses the data to create some visual representation.
I'm wondering if the current Google Glass supports wifi direct or other kind of
wifi p2p connection, and it can be used for the idea.
Or is Bluetooth the only available option for this kind of applications?
Thank you so much in advance.
Since Glass is basically Android, anything that would work on Android should work with it. I think websockets will do what you want, and there are multiple implementations of that for Android and other platforms.
That said, be sure to remember that Glass is a relatively weak system with a short battery life, so maintaining long lasting communications could be costly. Use caution.
I've been reading up on how to transfer data between iOS devices over Bluetooth using GameKit. I'm not writing a game, per se, but do have a need to transfer a small amount of binary data between two devices. Between two iOS devices, this is easy enough. However, I was wondering if it is possible to transfer data between an iOS device and an Android device via the same mechanism.
Has anyone come across documentation/tutorial that would explain how to do this? Is it even technically possible? Or has Apple put in some sort of restriction that would prevent this?
The other option I discovered was Bonjour over Bluetooth. Would this be a more suitable option for this type of operation?
This question has been asked many times on this site and the definitive answer is: NO, you can't connect an Android phone to an iPhone over Bluetooth, and YES Apple has restrictions that prevent this.
Some possible alternatives:
Bonjour over WiFi, as you mentioned. However, I couldn't find a comprehensive tutorial for it.
Some internet based sync service, like Dropbox, Google Drive, Amazon S3. These usually have libraries for several platforms.
Direct TCP/IP communication over sockets. (How to write a small (socket) server in iOS)
Bluetooth Low Energy will be possible once the issues on the Android side are solved (Communicating between iOS and Android with Bluetooth LE)
Coolest alternative: use the Bump API. It has iOS and Android support and really easy to integrate. For small payloads this can be the most convenient solution.
Details on why you can't connect an arbitrary device to the iPhone. iOS allows only some bluetooth profiles to be used without the Made For iPhone (MFi) certification (HPF, A2DP, MAP...). The Serial Port Profile that you would require to implement the communication is bound to MFi membership. Membership to this program provides you to the MFi authentication module that has to be added to your hardware and takes care of authenticating the device towards the iPhone. Android phones don't have this module, so even though the physical connection may be possible to build up, the authentication step will fail. iPhone to iPhone communication is possible as both ends are able to authenticate themselves.
Maybe a bit delayed, but technologies have evolved since so there is certainly new info around which draws fresh light on the matter...
As iOS has yet to open up an API for WiFi Direct and Multipeer Connectivity is iOS only, I believe the best way to approach this is to use BLE, which is supported by both platforms (some better than others).
On iOS a device can act both as a BLE Central and BLE Peripheral at the same time, on Android the situation is more complex as not all devices support the BLE Peripheral state. Also the Android BLE stack is very unstable (to date).
If your use case is feature driven, I would suggest to look at Frameworks and Libraries that can achieve cross platform communication for you, without you needing to build it up from scratch.
For example: http://p2pkit.io or google nearby
Disclaimer: I work for Uepaa, developing p2pkit.io for Android and iOS.
You could use p2pkit, or the free solution it was based on: https://github.com/GitGarage. Doesn't work very well, and its a fixer-upper for sure, but its, well, free. Works for small amounts of data transfer right now.
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.
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
I'm working on a cross-platform multiplayer game on android and ios.
I need to create a direct network connection between devices without a main server to be able to play without any internet access (e.g. in the metro).
I already tried this kind of game named "Skies of Glory" where the link between players were performed directly without internet access. Such as computer games, client players can see and connect on a game server created by one of players.
I was unable to find a "free" game framework able to provide this kind of network feature so I try to find out a standardized way to see host servers and etablish a communication without any user prompt thru a wireless connectivity (wifi or bluetooth). iOS and Android are separate worlds but most of network standards are supported by both platforms.
So how do it ?
I already excluded solutions:
Android's WIFI direct: not compatible with iOS and available on 4.x so it's too limited.
OSI's high level protocols because it suppose to be in the same managed network (so impossible in metro)
My leads
Turn one of the devices as a router but without user action.
Piconet technology if it's available on both OS.
If anybody have another idea ....
Thank you for your help
On iOS you could try using Bonjour http://en.wikipedia.org/wiki/Bonjour_(software) https://developer.apple.com/technologies/ios/networking.html but there is a reasonable amount of your own programming that would be needed to build what you need.
On Android you might be able to use zeroconf http://en.wikipedia.org/wiki/Zero_configuration_networking if you can find a suitable existing port or port it yourself using the NDK.