* The BLIPConnection receivedRequest: delegate method now returns BOOL. If the method returns NO (or if the method isn't implemented in the delegate), that means it didn't handle the message at all; an error will be returned to the sender.
* If the connection closes unexpectedly due to an error, then the auto-generated responses to pending requests will contain that error. This makes it easier to display a meaningful error message in the handler for the request.
5 // Created by Jens Alfke on 5/24/08.
6 // Copyright 2008 Jens Alfke. All rights reserved.
9 #import "BLIPEchoServer.h"
13 @implementation BLIPEchoServer
20 _listener = [[BLIPListener alloc] initWithPort: 12345];
21 _listener.delegate = self;
22 _listener.pickAvailablePort = YES;
23 _listener.bonjourServiceType = @"_blipecho._tcp";
25 NSLog(@"%@ is listening...",self);
37 - (void) listener: (TCPListener*)listener failedToOpen: (NSError*)error
39 NSLog(@"** %@ failed to open: %@",self,error);
42 - (void) listener: (TCPListener*)listener didAcceptConnection: (TCPConnection*)connection
44 NSLog(@"** %@ accepted %@",self,connection);
45 connection.delegate = self;
48 - (void) connection: (TCPConnection*)connection failedToOpen: (NSError*)error
50 NSLog(@"** %@ failedToOpen: %@",connection,error);
53 - (BOOL) connection: (BLIPConnection*)connection receivedRequest: (BLIPRequest*)request
55 NSLog(@"***** %@ received %@",connection,request);
56 [request respondWithData: request.body contentType: request.contentType];
64 int main( int argc, const char **argv )
66 NSAutoreleasePool *pool = [NSAutoreleasePool new];
67 BLIPEchoServer *listener = [[BLIPEchoServer alloc] init];
68 [[NSRunLoop currentRunLoop] run];