1

I'm starting a multiplayer game, but the examples show passing a NSData object that was created using a structure. With ARC though, I can't use C structures. (correct?) It seems that I'm supposed to use objects instead of C structures using ARC. But how do I send NSData packets of objects?

I guess I could hard code a big byte array, but it seems like there should be an easier way.

Also, if it is possible to send an object, how do I send multiple objects and be able to differentiate between the ones I send?

Thanks!

Nils Munch
  • 8,805
  • 11
  • 51
  • 103
  • today for networking I'd go for JSON encoded Strings instead of any binary stuff.. at least at the beginning – Daij-Djan Jan 01 '13 at 21:22

2 Answers2

1

ARC does not block you from using C structures, you just need to work a bit around the auto deallocation.

Also, if you want the quick and dirty way of handling it, you could disable ARC on your multiplayer manager, using this method.

Please describe which code you are following, and which ones are giving you problems.

Community
  • 1
  • 1
Nils Munch
  • 8,805
  • 11
  • 51
  • 103
  • I don't think I want to go about disabling ARC, as I'm new to objective-C, and haven't programmed without it. Is there any way to work within the ARC system? – samuel Schweighart Jan 02 '13 at 03:54
  • Fair enough, it was also a "quick and dirty" version. I have read the game-center documentation, and its fairly easy to convert to ARC. The tech demos given out at the WWDC2012 were arc as well, if you are a registered developer, you should have access to this. – Nils Munch Jan 02 '13 at 08:41
0

The answer to my question was to use a NSKeyedArchiver. It allows one to pack an object (or anything) into a NSData object.

  • The problem with this is that GameKit has a bug (as of today) that will occasionally stop receiving data with packet sizes > ~1000 bytes. If you use NSKeyedArchiver, your packets will get to big, and you may stop receiving data and your code will stop working. – samuel Schweighart Mar 03 '13 at 22:16