Re: NSStreamEventHasBytesAvailable not getting thrown
Re: NSStreamEventHasBytesAvailable not getting thrown
- Subject: Re: NSStreamEventHasBytesAvailable not getting thrown
- From: Bob Ippolito <email@hidden>
- Date: Tue, 27 Apr 2004 22:57:32 -0400
On Apr 27, 2004, at 10:48 PM, Adam wrote:
On Apr 27, 2004, at 10:13 PM, Bob Ippolito wrote:
On Apr 27, 2004, at 7:16 PM, Adam wrote:
I have modified some code written by Prachi to create a socket
stream object. His code was originally written to interact with a
GUI and I am trying to adapt it so that other objects (main in this
simple case) can connect to the server and send and receive commands
without the user and any GUI.
His GUI version works great but my class is getting stuck somewhere.
Based on the debugging strings I output with NSLog(), I am
successfully making a connection, but the
NSStreamEventHasBytesAvailable event is not getting called. So,
nothing is coming back after I make the connection. I am a newbie
coming over from the world of java to obj-c. If anyone could be of
help I would be grateful.
This code won't work without a NSRunLoop. The whole point of
CFSocket is that it's event driven and does not block, where the code
you are writing expects it to block. You either need to use blocking
sockets, or rewrite your code to be event driven. Apple's source for
mDNSResponder is a good example of how to do this for a non-GUI app,
but I'm sure there are others.
-bob
Please forgive my ignorance for the code I posted, but dont these two
lines in the connect method use a Run Loop:
[inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop]
forMode:NSDefaultRunLoopMode];
[outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop]
forMode:NSDefaultRunLoopMode];
Those lines schedule the streams on the current runloop, but your code
never starts the runloop so it's not going to do anything useful.
-bob
_______________________________________________
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.