• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NetSocket and parse line by line
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: NetSocket and parse line by line
      • From: "Philip Q" <email@hidden>
    • Re: NetSocket and parse line by line
      • From: Scott Stevenson <email@hidden>
  • Prev by Date: Drag and Drop with NSTable and Array controllers
  • Next by Date: Re: Can't get my application to see my Help Folder
  • Previous by thread: Re: Drag and Drop with NSTable and Array controllers
  • Next by thread: Re: NetSocket and parse line by line
  • Index(es):
    • Date
    • Thread