• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSData encoding issues...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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 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>)

  • Prev by Date: Re: NSData encoding issues...
  • Next by Date: Re: AB extensions
  • Previous by thread: Re: NSData encoding issues...
  • Next by thread: Re: AB extensions
  • Index(es):
    • Date
    • Thread