• 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: Dustin Voss <email@hidden>
  • Date: Tue, 30 Sep 2003 19:50:17 -0700

On Tuesday, September 30, 2003, at 12:50 PM, Alex Lock wrote:

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:
[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.

  • Follow-Ups:
    • Re: NSData encoding issues...
      • From: Alex Lock <email@hidden>
References: 
 >NSData encoding issues... (From: Alex Lock <email@hidden>)

  • Prev by Date: Re: Address Book Helper code released to public domain
  • Next by Date: Re: NSData encoding issues...
  • Previous by thread: NSData encoding issues...
  • Next by thread: Re: NSData encoding issues...
  • Index(es):
    • Date
    • Thread