NetSocket and parse line by line
NetSocket and parse line by line
- Subject: NetSocket and parse line by line
- From: "Hell's KItchen Hell's KItchen" <email@hidden>
- Date: Wed, 22 Nov 2006 13:02:45 +0100
Hello to all,
I'm playing with irc and I would to try to make a stupid client in
order to learn more about mac programming.
I'm not a cocoa expert but I know enough things ;)
However I've a problem.
I've used NetSocket from blackholemedia to manage connections.
Unfortunatly NetSocket don't have a parse line by line command and I
receive unformatted data. So I need to make a sort of buffer and send
each line when it's complete (it finish with a \r\n).
I've created this code, unfortunatly it does not work well and
sometimes it get wrong results. Anyone can help me? or anyone have a
better code? Thank you very much.
- (void)netsocket:(NetSocket*)inNetSocket dataAvailable:(unsigned)inAmount {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *str = [[[NSString alloc] initWithData: [inNetSocket
readData] encoding: NSASCIIStringEncoding]
autorelease];//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];
int len = cont-start;
if(stop != cont && cont-start >= 0) {
range.location = start;
range.length = cont - start;
[self _fetchRawData: [_string substringWithRange:range]];
} else {
}
}
while(stop != cont);
range.location = 0;
range.length = start;
[_string deleteCharactersInRange:range];
}
[pool release];
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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