Mailing Lists: Apple Mailing Lists

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

Re: NSData encoding issues...



On Tuesday, September 30, 2003, at 10:50 PM, Dustin Voss wrote:

[snipped]

It's probably freaking out because of the 255. How I'd handle this with AsyncSocket is to use readDataToData: to read one line at a time. Use an NSData of one byte, 255, as the ...ToData: parameter. Then use this:

int lineLength = [data length] - 1 /* to ignore the 255 */;
NSString *line = [NSString stringWithCString:[data bytes] length:lineLength];

That should work.
_______________________________________________
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.

Thanks for the tip! I'll give that a try tomorrow!

To be honest, I hope it works... as I said before I love the way you have the delegation set up... remarkably simple to understand/use. Makes SmallSockets look really obfuscated by comparison (though SmallSockets has different goals, mainly to be small/simple; which it accomplishes in excellent fashion).

Again, great work (and thanks again for the tip).

Oh, one quick question; to write the same type of (terminated by 0xFF) cstring using writeData: (from the source of an NSString) should I just use:

myString = [myString stringByAppendingFormat:@"%c",255]; //where myString is the NSString containing the info I'd like to send
[socket writeData:[NSData dataWithBytes:[myString cString] :[myString length]*sizeof(char)-1]]]; //-1 to ignore the \0 terminator

Would that work to transmit an NSString as a clear cString w/ an unsigned 0xFF terminator (i.e., mimic the direct send(socketfd, &charbuf, length, 0); call I outlined previously)?

Thanks again for your help!

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.

References: 
 >Re: NSData encoding issues... (From: Dustin Voss <email@hidden>)



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.