Reading NSInputStream
Reading NSInputStream
- Subject: Reading NSInputStream
- From: Ashley Perrien <email@hidden>
- Date: Wed, 21 Oct 2009 15:04:00 -0500
I'm writing a small application to get info from a mail server and
having lots of problems with reading from NSInputStream. After
initiating a connection (getStreamsToHost) I don't get an event that
the input stream has bytes available, if I check it, it returns NO but
if I go ahead and read it anyway, I get the usual banner. I'm also
unable to get the buffers working.
So 1) I can't get this working at all:
uint8_t *readBuffer;
unsigned int bufferLength;
BOOL gotBuffer = [readStream getBuffer: &readBuffer length:
&bufferLength];
The last line always says arguments 1 and/or 2 are incompatible
pointer type. I've tried every combination of * and &, no luck.
If instead I go with NSData:
if ([readStream hasBytesAvailable])
NSLog(@"Has Bytes");
else
NSLog(@"No Bytes");
NSMutableData *returnMessage = [NSMutableData dataWithLength: 300];
[readStream read: [returnMessage mutableBytes] maxLength: 300];
NSString *readData = [[NSString alloc] initWithBytes: [returnMessage
bytes] length: 300 encoding: NSUTF8StringEncoding];
NSLog(@"Read: %@", readData);
I get:
No Bytes
Read: 220 mx.google.com ESMTP...
So, how do you go about finding out if there's something available,
getting a buffer and reading into it? I've searched the archives and
google, copy and pasted the code and it still returns errors or gets
results that don't make sense (no bytes available but they read in
fine).
Ashley Perrien
P.S. I know there are other mail frameworks out there, I'm not looking
to actually send and receive anything substantial, just want to
reliably connect to the server, send ehlo or .capability and capture
the result, that's all. I've been beating my head against a wall for a
while now trying to get it to work without knowing if there's actually
data to be read and how best to do it.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden