Re: NSData Question
Re: NSData Question
- Subject: Re: NSData Question
- From: Alex Lock <email@hidden>
- Date: Thu, 9 Oct 2003 10:00:19 -0400
On Thursday, October 9, 2003, at 09:29 AM, David Dauer wrote:
Hello
I'm using an AGSocket (UDP) and want to send some data through it.
AGSocket *socket;
//...
socket = [[AGSocket udpSocket] retain];
//...
[socket writeData:data toAddress:remoteAddr];
I know what I have to do in php, there the data to send is:
"\xFF\xFF\xFF\xFFmyCommand\n"
And i know that FF is 255 in decimal in the ascii table.
My problem is that i don't know how i can add this value to the NSData
*data.
Thanks for any help
David
Wow, glad you asked this when you did:) I struggled with something
very similar recently. If you just need 4 0xFF chars in there, the
easiest thing to do would be:
NSData *myData = [[NSString
stringWithFormat:@"%c%c%c%cmyCommand\n",0xFF,0xFF,0xFF,0xFF]
dataWithEncoding:<your encoding here>];
If that doesn't suit you, you can also declare the 0xFF as a single
Byte by:
Byte myBytes[4] = {0xFF, 0xFF, 0xFF, 0xFF};
Then create an NSMutableData with those bytes to start, and append the
string you want to send using appendData with the dataUsingEncoding
message outlined above.
Hope that helps!
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.