开发者

Any sample project that shows how to use gamekit (server-client model) WITHOUT(!) GKPeerPickerController and more than 2 devices?

开发者 https://www.devze.com 2023-03-04 05:14 出处:网络
is there any sample project that shows how to use gamekit without gkpeerpicker? And is there any sample that uses bonjour (but without any internet connection and no wireless router)?

is there any sample project that shows how to use gamekit without gkpeerpicker? And is there any sample that uses bonjour (but without any internet connection and no wireless router)? Some informations (for both projects):

  • only bluetooth (bonjour for the other project)
  • more than 2 devices (if possible)
  • server client model (how to make it work)
  • send/receive data
  • the server can decide whether is is "visible" for other "potenial" clients
  • show in a tableview the "discoverd" devices -> if the user clicks on a tableview cell (the name of the device e.g. "Tom's iPod Touch") it is going to pair up but the other user must accept the connection (UIAlert开发者_StackOverflow中文版View) and if he accepts they will pair up
  • show all connected peers (connected to the server) in a uitableview
  • kick out some peers (only the server can kick other) (this should be easy to implement. just send a special packet to the client with a string that says "KICK YOURSELF" than it will kick itself)
  • invite other clients (in search) (don't really need this but would be awesome):
  • let clients/server move objects (physic objects in box2d (cocos2d)) and than every client should show the exactly same simulation on the screen.

After using google for some hours I think there's no sample project(s) that shows these "features" above. Mayby someone could make one? Please do not say me some theory. I read so much but a sample project (or more and another for the bonjour version) with code commentary would be great!

Edit: I will probably add some bounty on this ;). Currently I can't ;)

Thank you very much for reading :)

cocos2dbeginner


I'm not going to write this for you but I can help with some information to get you started. There are many examples that show some of your features, particularly Apple's witap example.

One thing to note, you can't go from bluetooth to bonjour. bluetooth is the method of communication, bonjour is how you communicate. So you'd have to do bonjour broadcasting on one side and connecting on the other. Bonjour over bluetooth is taken care of in Apple's API, it should "just work". See this for some more info here.

This page from apple not only has gamekit concepts you are looking for but it also tells you the method names you will be using to get your tasks done, even if you don't want to be going through the supplied UI that apple has with GameKit.

Here, here, here, and here are links for more bonjour networking samples. As long as you're not doing complex tasks with sockets, I like this personally, it makes things very simple.

Hope that helps some.


I highly recommend Ray Wenderlichs page. There is a tutorial for Gamecenter networking that matches some of your requests. http://www.raywenderlich.com/3276/how-to-make-a-simple-multiplayer-game-with-game-center-tutorial-part-12

According to your alias: There are many more useful tutorials with a high quality. Go to http://www.raywenderlich.com/tutorials for a list.


Apple themselves have demo projects that show wifi connections using GKSession and Bluetooth using GKPeerPickerController. If you wanted a peerPicker and an option for both I think you need to use a peerpicker controller to give the user a choice. Use this code at the point you want the picker to appear, after you have instantiated the picker.

picker.connectionTypesMask = GKPeerPickerConnectionTypeOnline | GKPeerPickerConnectionTypeNearby;

Then if they choose wifi use the code from the GKRocket project in the iOS Sample Code Library. If they choose Bluetooth then use GKTank.

The GKRocket code (using GKSession and tables) is much harder to follow but GKSession automatically uses bluetooth if there is no wifi coverage. Given that you will need most of the code for GKSession in your project to handle wifi I think it is easier to forget about peerPickerController unless you only want bluetooth.

Eventually Apple will surely add the necessary methods and properties to peerPickerController to handle wifi, but for the moment it is GKSession you need.

Hope it helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消