[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
NSInputStream event question
From: |
Tima |
Subject: |
NSInputStream event question |
Date: |
Sat, 27 Jan 2007 21:16:16 -0800 |
User-agent: |
GNUMail (Version 1.2.0) |
Hi list,
I've send similar question before, but I'm not sure it did get through.
Sorry if you see the duplicate.
I'm learning how to work with NSStreams. I made an application
that uses NSInput/OutputStream pair for local socket.
Everything works as expected (base-1.13, gui-0.11, Linux) except that
I do not get NSEventErrorOccurred in the case of errors, when the
server
process is stopped, for instance, or there is no socket file.
Please see the code below - do I miss anything?
In the case of no /tmp/jsond file I get
2007-01-27 21:10:30.956 StreamAppTest[8574] Setting stream from local
socket /tmp/jsond
2007-01-27 21:10:30.957 StreamAppTest[8574] <GSLocalInputStream:
8258390> error(2): - No such file or directory
but expect to see my own printing, something like
2007-01-27 21:10:30.956 StreamAppTest[8574] Setting stream from local
socket /tmp/jsond
2007-01-27 21:10:30.957 StreamAppTest[8574] AppController:
NSStreamEvent=8
Thanks a lot,
--Tima.
Here is the complete code of the application.
------------------------StreamAppTest.m begin------------------------
#include <AppKit/AppKit.h>
@interface AppController : NSObject
{
NSInputStream * iStream;
NSOutputStream * oStream;
}
- (void) applicationWillFinishLaunching: (NSNotification *)not;
- (void) startIO;
- (void) stream: (NSStream *)theStream handleEvent:
(NSStreamEvent)streamEvent;
@end
@implementation AppController : NSObject
- (void) startIO
{
NSString * path = @"/tmp/jsond";
NSLog( @"Setting stream from local socket %@", path );
[NSStream getLocalStreamsToPath: path inputStream: &iStream
outputStream: &oStream];
[iStream setDelegate: self];
[iStream scheduleInRunLoop: [NSRunLoop currentRunLoop]
forMode: NSDefaultRunLoopMode];
[iStream open];
[oStream open];
}
- (void) stream: (NSStream *)stream handleEvent:
(NSStreamEvent)streamEvent
{
NSLog(@"AppController: NSStreamEvent=%d", streamEvent);
}
- (void) createMenu
{
NSMenu * menu = [[NSMenu new] autorelease];
[NSApp setMainMenu: menu];
[menu addItemWithTitle:@"Quit"
action:@selector(terminate:)
keyEquivalent:@"q"];
}
- (void) applicationWillFinishLaunching: (NSNotification *)not
{
[self createMenu];
[self startIO];
}
@end
int main (int argc, const char **argv)
{
[NSApplication sharedApplication];
[NSApp setDelegate: [AppController new]];
return NSApplicationMain (argc, argv);
}
------------------------------- StreamAppTest.m end
----------------------------
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- NSInputStream event question,
Tima <=