Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > NSData and sockets...

NSData and sockets...
Thread Tools
juanpacolopez
Dedicated MacNNer
Join Date: May 2003
Location: Atlanta, GA
Status: Offline
Reply With Quote
Sep 30, 2003, 03:03 PM
 
Hey all,

Another (sort of) networking question for you:

I ditched SmallSockets and starting using AsyncSocket, as it's small (very) and supports delegation (which I wanted very badly) via CFSocket and related classes...

Here's my problem...

The protocol I'm using (not mine, so don't mock, I know it sucks hard) sends EVERYTHING directly to/from the (raw) socket with no encoding as in:

send(socketfd, &charbuf, length, 0);
recv(socketfd, &incharbuf, length, 0);

My question is this... if I'm using AsyncSocket (which encapsulates all data send/recieved inside an NSData object) how can I access this data properly (as text)?

I've tried using NSString's initWithData:encoding: method to access the data in a more readable sense... I've also tried using NSData's getBytes method to dump it directly into an unsigned character array... both of these approaches produce garbage.

So... how can I (properly) dump an NSString as plain (unencoded) text into an NSData object, and conversely how can I convert said NSData object back to it's string representation?

Thanks for any help!
Alex

G7 Software: home Tetrinet Aqua
-----
"Utopia" 1Ghz TiBook SuperDrive w/ 1Gb RAM.
     
K++
Senior User
Join Date: Jan 2002
Location: NYC
Status: Offline
Reply With Quote
Sep 30, 2003, 10:41 PM
 
Im gonna once again suggest NetSocket. I have used it for almost the exact same thing for a certain file sharing protocol and it works and exactly how is expected. Add to that it is small and easy to use as well as Asynchronous. I have been using it since 0.3 and since it is open source it has been updated several times since and is now 0.9 with new features.

http://www.blackholemedia.com/code

Why not just use that?
     
juanpacolopez  (op)
Dedicated MacNNer
Join Date: May 2003
Location: Atlanta, GA
Status: Offline
Reply With Quote
Oct 1, 2003, 12:39 AM
 
Originally posted by K++:
Im gonna once again suggest NetSocket. I have used it for almost the exact same thing for a certain file sharing protocol and it works and exactly how is expected. Add to that it is small and easy to use as well as Asynchronous. I have been using it since 0.3 and since it is open source it has been updated several times since and is now 0.9 with new features.

http://www.blackholemedia.com/code

Why not just use that?
Even if I used NetSocket, it would still offer the same problem;

That is, representing a cstring inside an NSData object terminated by unsigned 0xFF rather than a typical CR/LF or even \0 (if no newline char).

From what I can tell, NetSocket is unbuffered?

I'll look at it more closely tomorrow...

thanks for the tip!
Alex

G7 Software: home Tetrinet Aqua
-----
"Utopia" 1Ghz TiBook SuperDrive w/ 1Gb RAM.
     
K++
Senior User
Join Date: Jan 2002
Location: NYC
Status: Offline
Reply With Quote
Oct 1, 2003, 02:36 PM
 
Originally posted by juanpacolopez:
Even if I used NetSocket, it would still offer the same problem;

That is, representing a cstring inside an NSData object terminated by unsigned 0xFF rather than a typical CR/LF or even \0 (if no newline char).

From what I can tell, NetSocket is unbuffered?

I'll look at it more closely tomorrow...

thanks for the tip!
NetSocket is buffered and has an actual method for doing exactly what you want, which is to read a C string from the network. I know this works since my DC client works by doing just that over and over again.
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 08:22 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,