Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSData encoding issues...



Hey all,

So I've got a socket problem. Actually it's not so much a socket problem as it is an NSData problem.

I'm working on an app where (unfortunately) the networking protocols are already written/being used...

All communication (in existing versions) is handled by directly writing characters to the socket, as in:

send (socketfd, &charbuf, length, 0);
recv (socketfd, &charbuf, length, 0);

Where the character buffers are regular (unterminated) C strings. For a new-line delimeter, it uses unsigned char 0xFF (int 255).

Here's the problem... I've tried OmniNetworking, SmallSockets, and now AsyncSockets (which I like best because it supports delegation exactly the way I would implement it myself); they all offer the same problem, text encoding.

Since all data sent to/received from the server in these classes is encapsulated inside an NSData object, I can't simply reference characters directly as I would if I was using the above (raw) socket functions. I've tried using:

[[NSString alloc] initWithData:[myData dataWithEncoding:[NSString defaultCStringEncoding]]];

To give me a "readable" string from the incoming bytes, but this doesn't seem to work...

I've tried using NSData's getBytes:length: method to copy it into a character buffer (which I could then convert to a cstring and copy into an NSString), still doesn't work...

My question is, if data is being sent/received from the server in the manner outlined above, what is the "proper" way to deal with said data using the NSData object?

Or, am I wasting my time w/ NSData? Is it really necessary for me to write my own socket class just to handle clear-text communication?

Thanks!

Alex <email@hidden>
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.