• 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
Reading from an NSInputStream
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Reading from an NSInputStream


  • Subject: Reading from an NSInputStream
  • From: Evan DiBiase <email@hidden>
  • Date: Sat, 22 Nov 2003 11:21:29 -0500

Hello!

I'm attempting to create a simple network application (an IRC client to be exact, mostly for learning purposes) using the NSStream class. My code uses [NSStream getStreamsToHost:port:inputStream:outputStream] to get NSInputStream and NSOutputStream instances, assigns a delegate to those instances, schedules each instance into [NSRunLoop currentRunLoop], and then opens them.

Connection goes swimmingly; my delegate receives two NSStreamEventOpenCompleted events (one for the input stream and for the output stream, I presume) and, after the streams are open, receives a NSStreamHasBytesAvailableEvent. I'm having trouble actually reading bytes from the input stream once I've received the event, however.

When I get NSStreamHasBytesAvailableEvent, I simply invoke a method of my own creation:

- (void)readBytes:(NSInputStream *)stream
{
if (![stream hasBytesAvailable]) {
return;
} else {
uint8_t *buf;
unsigned int *numBytes;
[stream getBuffer:&buf length:numBytes];
for (int i = 0; i < *numBytes; i++) {
printf("%c", buf[i]);
}
}
}

Once the code hits here, however, the application receives signal 11 underneath the [inputStream getBuffer:&buf length:numBytes] call, in Apple's code.

I imagine I'm doing something drastically wrong here, but I can't for the life of me figure out what it is. Any help would be greatly appreciated.

Thanks,
Evan
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Reading from an NSInputStream
      • From: Troy Dawson <email@hidden>
  • Prev by Date: Re: Where to set default user defaults?
  • Next by Date: AppleScript Integration
  • Previous by thread: Re: Search Kit memory use
  • Next by thread: Re: Reading from an NSInputStream
  • Index(es):
    • Date
    • Thread