3

I'm programming an iOS application which needs to communicate with a python app in a very effecient way thru UDP sockets.

In the middle I have a bonjour service which serves as a bridge for my iOS app and host python app to communicate.

I'm building my own protocol which is a simple C structure. The code that I had already as packing strings into NSKeyedArchiver entities which by their turn would be packed in NSData and sent. In the other side there is a NSKeyedUnarchiver.

The problem is that it can't understand the C struct i'm sending. Is there a way of putting a C structure inside a NSKeyedArchiver? How should I modify my middle service to remove this?

Nuno Santos
  • 1,476
  • 3
  • 17
  • 34

2 Answers2

4

Yes, it is possible.

Read the Archives and Serializations Programming Guide, everything is explained here with samples, including this case, especially the part Encoding and decoding C Data Types :)

AliSoftware
  • 32,623
  • 6
  • 82
  • 77
-1

Rather than use NSData - and if the struct contains simple data items, rather than objects pointers you can use NSValue

NSValue valueFromStruct = [[NSValue value:&aStruct withObjCType:@encode(YourStructType)] retain];

As NSValue conforms to the NSCoding protocol you can use the methods that you want to use.

Abizern
  • 146,289
  • 39
  • 203
  • 257