Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>So, looking at your <code>NSStreamDelegate</code>, it looks like you haven't implemented all of the cases for that switch statement. I recently wrote an IRC client for OS X that uses <code>NSStream</code> and <code>NSStreamDelegate</code> in a very similar way, and I'm pretty sure that the compiler should complain when you haven't checked for all of the cases there.</p> <p>Looking back to <a href="https://github.com/tjarratt/twIRCk/blob/master/TwIRCk/GLGReadDelegate.m" rel="nofollow">some of my code</a> it looks like you should be checking for the cases </p> <ul> <li><code>NSStreamEventHasSpaceAvailable</code></li> <li><code>NSStreamEventOpenCompleted</code></li> <li><code>NSStreamEventHasBytesAvailable</code></li> <li><code>NSStreamEventEndEncountered</code></li> <li><code>NSStreamEventErrorOccurred</code></li> </ul> <p>So the case you haven't checked for is <code>NSStreamEventHasSpaceAvailable</code>, which is when you can start writing to your stream.</p> <p>edit: Reading your code again, I see in your <code>sendMessage</code> action that you're using the <code>outputStream</code> object instead of the delegate to write, and then doing the work yourself to read from the <code>inputStream</code>. I think you probably want to use the delegate and never read directly from your inputstream because it will greatly simplify how your code receives data from the network. From what I understand, <code>NSStream</code> is there to provide a small layer of abstraction around the fact that data is buffered from the network so you don't need to do things like call <code>usleep</code> while your inputstream does not have bytes available to read.</p> <p>edit2: I read your update about your code never getting past <code>while (![inputStream hasBytesAvailable])</code> and it seems pretty clear that the problem is that you're not using your streams correctly. The way I see it, the best way to use <code>NSStream</code> is to respond to events, using its <code>handleEvent:(NSStreamEvent) event</code> method, and never directly tell it to write bytes, or to sleep until it has bytes available.</p> <p>In the code I linked to you, I have a readDelegate and a writeDelegate that both handle <code>NSStreams</code>, you might want to take a look at how I use my writeDelegate <a href="https://github.com/tjarratt/twIRCk/blob/master/TwIRCk/GLGWriteDelegate.m" rel="nofollow">here</a>. I basically have a method, <code>addCommand:(NSString *) command</code> that puts a string to write to the stream into a queue, and then when my stream delegate can write bytes (<code>NSStreamEventHasSpaceAvailable</code>), I write as many bytes as I can. I hope this helps!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload