IPhone P2P - Problem with p2p connection when 3 iphones are searching - iphone

Here's the situation, I made a game that use GKSessionModePeer to do the multiplay mode, but the problem is happened when I use three iphones, just call them A,B,C
when A and C searched B,they choose B at the same time, then the screen change to the waiting for apply page,
at this moment,problem happen!!!!!
A and C start the game suddenly with no connection from each other ,B's screen show "Do you accept the connection" page, after a second A and C lost connection, what's happen???
I want iphone would accept connection one by one, A and C will not start the game suddenly,
what should i do???
Can anyone help me???

According to the GameKit framework reference:
Game Kit offers your applications the ability to create Bluetooth connections between two devices.
http://developer.apple.com/iphone/library/documentation/GameKit/Reference/GameKit_Collection/GameKit_Collection.pdf
Using GameKit to setup a game for more than 2 players won't work. You'll need to use another solution, such as one of the devices hosting a server and using a wifi network.

Related

Peer-to-peer communication between iOS devices

I am trying to prototype a solution to a problem and am currently exploring multiple routes I could try. Is it possible for one iOS device, running a certain app, to communicate directly with another iOS device, running the same application - without the need to be on the same LAN?
Solutions I am currently investigating are using Bluetooth and ad-hoc wireless connections.
Ideally, the application when installed would ask the user for the required permissions, and then would accept and/or send data to/from another client after a handshake had happened.
My concern with Bluetooth is that 'pairing' would need to happen with every device, rather than happen in the background once the user has installed the app. I have a feeling what I am talking about isn't possible from what I've been reading elsewhere on Stackoverflow.
Take a look at Bluetooth Low Energy.
https://developer.apple.com/library/ios/#samplecode/BTLE_Transfer/Introduction/Intro.html#//apple_ref/doc/uid/DTS40012927
Here is another example,
https://github.com/KhaosT/CBPeripheralManager-Demo
You might also want to look into GameKit and peer-to-peer connectivity there.
I can't tell you anything about it, but you might try looking at iOS 7. If that's an option, I'd take a look. Can't talk about what it is because of NDA though.
Depending on what you need to communicate, you could try checking out this project, which lets you share arrays of strings between iOS devices over Bluetooth LE.
You don't need to "pair" the devices and it can still communicate while the app is in the background. SimpleShare
Hope it helps!
From the documentation of MultipeerGroupChat:
MultipeerGroupChat sample application utilizes the Multipeer Connectivity framework to enable nearby users to discover, connected, and send data between each other. This sample simulates a simple chat interface where up to 8 devices can connect with each other and send text messages or images to each other. Here you will learn how to bring up framework UI for discovery and connections and also how to monitor session state, listen for incoming data and resources, and send data and resources.
This is an excellent example at developer.apple.com here is the link
https://developer.apple.com/library/ios/samplecode/MultipeerGroupChat/Introduction/Intro.html
Also this tutorial from Ralf Ebert demonstrates how to use Multipeer Connectivity framework for peer communication should help you.
https://www.ralfebert.de/tutorials/ios-swift-multipeer-connectivity/

Send messages between iPhone & Mac

I'm fairly novice in iPhone development, but trying to create what would seem a fairly simple application.
I want to have 1 program running on my phone/simulator that has a slider and a button, and another receiving program on the mac, such as Processing/Supercollider.
When the button is pressed i want a String such as "hello" to appear in the post window of the program on the mac, and when the slider is moved up/down for an integer, say between 0-99, to correspond with the movement on the phone. I'm assuming a WiFi connection would be essential for the sending of messages between devices.
Does anyone know how I might go about writing this - tutorials/code examples/links to get me started?
Cheers
cocoaasyncsocket is a great wrapper around CFSocket and CFStream, that makes networking much easier. Bonjour has great documentation at developer.apple.com
This should be done over a TCP connection which is established between your iPhone and the PC. For that to happen you need to write 2 pieces of software:
1) A client: to be installed on your iPhone
2) A server: to be installed on your PC
The server will listen to connections coming from the iPhone and once a connection is made you can send messages quite easily between the two.
This will give you a good grasp on the theory
Guide to socket programming in C
Once you have that then you can find tons of Obj-C TCP examples.

Is it possibile to connect two iphones via wifi without a LAN?

I need two iphones to communicate (send and receive messages) without being inside a LAN.
I read that Game Kit Framework makes this possibile but only via bluetooth (is that right?). The application that I have to create need a larger radius than bluetooth so I need wifi but I can't have a Laptop that create the network 'cause this application will run on the outside just between iphone (without internet connection).
Is that possibile?
In that case, where do I have to take a look? (Bonjour, Game Kit Framework..)
Thank you
Here's the deal ...
GameKit works with EITHER bluetooth or wifi. It's completely automatic. Annoyingly you CAN NOT choose between the paradigm.
From 2016, almost all iPhones / iPads can create a "hotspot" WiFi network, yes.

How to use multiple peers with GameKit on iPad with iPhones?

If I am developing an iPad app (the "Server") which needs to communicate with up to 4 iPhone/iPod Touches (the Clients) how can I manage this?
The two apps will be separate. Should I create 4 GKSessions for each of the iPhones? Should I have 1 GKSession which connects all 5 devices, and if I do, will each iPhone be able to "see" the others (Ideally, this shouldn't happen as it will keep things simple)? The apps will together be a bit like the Scrabble app for iPad (not in functionality, but in idea). How should I manage this?
Thanks in advance, and please comment if you need more information.
You should create a single session on the iPad, advertise it as a Server, and look for that session from each iPhone in client mode. The iPad should keep an array that has each peerID that is connected to it, most likely connected to or as part of some kind of array of controller or player objects. Since each iPhone is set to be a client, they only will be able to see the server session being advertised by the iPad, not the client signals coming from the other iPads.
If you want an iPhone to be able to signal another iPhone, you can pass out the array of peerIDs to each iPhone through some kind of messaging object, which will allow any particular iPhone to send a message directly to another iPhone.
I'm doing something similar with 1 or 2 iPads and up to 10 iPhones or iPad touches. With 2 iPads the game board gets expanded, and it allows more than 5 players.

iPod touches cannot find each other through GameKit

I have two physical iPod touch devices. If I try running a program that uses a GKPeerPickerController to find another iPod touch running the same program, they just stay at the peer picker screen without any progress. Both have bluetooth enabled. I have tried my own program, along with Apple's GKTank sample app. Neither of the iPods seem to be able to detect bluetooth devices, such as computers in discoverable mode... could this have anything to do with it?
I was able to fix this problem by restoring the software on the older iPod. I wonder if jailbreak may have caused this issue?
A couple assumptions are throwing you off:
The GameKit Bluetooth stuff runs its own protocol, which doesn't involve traditional Bluetooth pairing or discoverability.
The simulator doesn't support connecting to devices via GameKit, so you need to test this with two real devices (or two computers, as the simulator will run the GK protocol over your current TCP connection [ethernet, wifi, etc]).
The Bluetooth bring-up of TCP/IP and Bonjour is really slow, so your first connection will often take upwards of 30 seconds to do any discovery. Even then, it seems flaky to me.
Jailbreaking your iPhone puts everything in play. You should expect stuff to not work, and be grateful if/when it does.
Gamekit only work on second generation iPod Touches (and iPhone 3G and 3GS). You didn't say whether what version your touches are.
I have been getting this error throughout the development of my game. It also leads to other problems when trying to reconnect to another game as the peer picker takes ages to connect so users get impatient. Apple needs to work on getting this more reliable.
I have restored my ipods now so will be interested to see the outcome.