1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/BLIP/Demo/BLIPEchoServer.m Wed Jun 04 21:09:45 2008 -0700
1.3 @@ -0,0 +1,70 @@
1.4 +//
1.5 +// BLIPEchoServer.m
1.6 +// MYNetwork
1.7 +//
1.8 +// Created by Jens Alfke on 5/24/08.
1.9 +// Copyright 2008 Jens Alfke. All rights reserved.
1.10 +//
1.11 +
1.12 +#import "BLIPEchoServer.h"
1.13 +#import "BLIP.h"
1.14 +
1.15 +
1.16 +@implementation BLIPEchoServer
1.17 +
1.18 +
1.19 +- (id) init
1.20 +{
1.21 + self = [super init];
1.22 + if (self != nil) {
1.23 + _listener = [[BLIPListener alloc] initWithPort: 12345];
1.24 + _listener.delegate = self;
1.25 + _listener.pickAvailablePort = YES;
1.26 + _listener.bonjourServiceType = @"_blipecho._tcp";
1.27 + [_listener open];
1.28 + NSLog(@"%@ is listening...",self);
1.29 + }
1.30 + return self;
1.31 +}
1.32 +
1.33 +- (void) dealloc
1.34 +{
1.35 + [_listener close];
1.36 + [_listener release];
1.37 + [super dealloc];
1.38 +}
1.39 +
1.40 +- (void) listener: (TCPListener*)listener failedToOpen: (NSError*)error
1.41 +{
1.42 + NSLog(@"** %@ failed to open: %@",self,error);
1.43 +}
1.44 +
1.45 +- (void) listener: (TCPListener*)listener didAcceptConnection: (TCPConnection*)connection
1.46 +{
1.47 + NSLog(@"** %@ accepted %@",self,connection);
1.48 + connection.delegate = self;
1.49 +}
1.50 +
1.51 +- (void) connection: (TCPConnection*)connection failedToOpen: (NSError*)error
1.52 +{
1.53 + NSLog(@"** %@ failedToOpen: %@",connection,error);
1.54 +}
1.55 +
1.56 +- (void) connection: (BLIPConnection*)connection receivedRequest: (BLIPRequest*)request
1.57 +{
1.58 + NSLog(@"***** %@ received %@",connection,request);
1.59 + [request respondWithData: request.body contentType: request.contentType];
1.60 +}
1.61 +
1.62 +
1.63 +@end
1.64 +
1.65 +
1.66 +int main( int argc, const char **argv )
1.67 +{
1.68 + NSAutoreleasePool *pool = [NSAutoreleasePool new];
1.69 + BLIPEchoServer *listener = [[BLIPEchoServer alloc] init];
1.70 + [[NSRunLoop currentRunLoop] run];
1.71 + [listener release];
1.72 + [pool drain];
1.73 +}