jens@3: // jens@3: // BLIPEchoServer.m jens@3: // MYNetwork jens@3: // jens@3: // Created by Jens Alfke on 5/24/08. jens@3: // Copyright 2008 Jens Alfke. All rights reserved. jens@3: // jens@3: jens@3: #import "BLIPEchoServer.h" jens@26: #import "MYNetwork.h" jens@3: jens@3: jens@3: @implementation BLIPEchoServer jens@3: jens@3: jens@3: - (id) init jens@3: { jens@3: self = [super init]; jens@3: if (self != nil) { jens@3: _listener = [[BLIPListener alloc] initWithPort: 12345]; jens@3: _listener.delegate = self; jens@3: _listener.pickAvailablePort = YES; jens@3: _listener.bonjourServiceType = @"_blipecho._tcp"; jens@3: [_listener open]; jens@3: NSLog(@"%@ is listening...",self); jens@3: } jens@3: return self; jens@3: } jens@3: jens@3: - (void) dealloc jens@3: { jens@3: [_listener close]; jens@3: [_listener release]; jens@3: [super dealloc]; jens@3: } jens@3: jens@3: - (void) listener: (TCPListener*)listener failedToOpen: (NSError*)error jens@3: { jens@3: NSLog(@"** %@ failed to open: %@",self,error); jens@3: } jens@3: jens@3: - (void) listener: (TCPListener*)listener didAcceptConnection: (TCPConnection*)connection jens@3: { jens@3: NSLog(@"** %@ accepted %@",self,connection); jens@3: connection.delegate = self; jens@3: } jens@3: jens@3: - (void) connection: (TCPConnection*)connection failedToOpen: (NSError*)error jens@3: { jens@3: NSLog(@"** %@ failedToOpen: %@",connection,error); jens@3: } jens@3: jens@63: - (BOOL) connection: (BLIPConnection*)connection receivedRequest: (BLIPRequest*)request jens@3: { jens@3: NSLog(@"***** %@ received %@",connection,request); jens@3: [request respondWithData: request.body contentType: request.contentType]; jens@63: return YES; jens@3: } jens@3: jens@3: jens@3: @end jens@3: jens@3: jens@3: int main( int argc, const char **argv ) jens@3: { jens@3: NSAutoreleasePool *pool = [NSAutoreleasePool new]; jens@3: BLIPEchoServer *listener = [[BLIPEchoServer alloc] init]; jens@3: [[NSRunLoop currentRunLoop] run]; jens@3: [listener release]; jens@3: [pool drain]; jens@3: }