Re: NSData encoding issues...
Re: NSData encoding issues...
- Subject: Re: NSData encoding issues...
- From: Alex Lock <email@hidden>
- Date: Tue, 30 Sep 2003 23:39:31 -0400
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 write
Data:[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.