AsyncSocket and buffer for line
AsyncSocket and buffer for line
- Subject: AsyncSocket and buffer for line
- From: malcom <email@hidden>
- Date: Sun, 20 Aug 2006 10:23:42 +0200
Hello, I would to use AsyncSocket to receive data from server.
I've tried to use NNTP protocol so I need to check if a received line
it's equal to @"." to see if an article text has received.
Unfortunatly AsyncSocket did not return to me a "real server line" but
only the partial received data.
So sometimes instead of receiving
blal bla bla
I could receive
bla bla
bla
but there is not any second line in original text.
How can I make a sort of buffer that merge these fake lines?
I've tried this but it seems not work.
-(void)onSocket:(AsyncSocket *)sock didReadData:(NSData*)data withTag:(long)t {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *str = [[[NSString alloc] initWithData:data
encoding:NSISOLatin1StringEncoding] autorelease];
NSRange range;
if(!_string) _string = [[NSMutableString alloc] init];
if(str && [str length] > 0) {
unsigned int start, stop, cont;
[_string appendString:str];
start = stop = cont = 0;
do {
range.location = stop;
range.length = 0;
[_string getLineStart:&start end:&stop contentsEnd:&cont
forRange:range];
if(stop != cont) {
range.location = start;
range.length = cont - start;
[self _preFetchRawData: [_string substringWithRange:range]];
}
}
while(stop != cont);
range.location = 0;
range.length = start;
[_string deleteCharactersInRange:range];
}
[pool release];
[socket readDataWithTimeout: timeout tag: 1];
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden