Removed unnecessary files. Toned down logging. Added null logging handler to BLIP so client code doesn't have to use logging. Modified test drivers to work against Cocoa versions.
2 #import "MyViewController.h"
6 @implementation MyViewController
13 // When the user starts typing, show the clear button in the text field.
14 textField.clearButtonMode = UITextFieldViewModeWhileEditing;
16 label.text = @"Opening listener socket...";
18 _listener = [[BLIPListener alloc] initWithPort: 12345];
19 _listener.delegate = self;
20 _listener.pickAvailablePort = YES;
21 _listener.bonjourServiceType = @"_blipecho._tcp";
26 - (void)updateString {
28 // Store the text of the text field in the 'string' instance variable.
29 self.string = textField.text;
30 // Set the text of the label to the value of the 'string' instance variable.
31 label.text = self.string;
35 - (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
36 // When the user presses return, take focus away from the text field so that the keyboard is dismissed.
37 if (theTextField == textField) {
38 [textField resignFirstResponder];
39 // Invoke the method that changes the greeting.
46 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
48 // Dismiss the keyboard when the view outside the text field is touched.
49 [textField resignFirstResponder];
50 // Revert the text field to the previous value.
51 [super touchesBegan:touches withEvent:event];
66 #pragma mark BLIP Listener Delegate:
69 - (void) listenerDidOpen: (TCPListener*)listener
71 label.text = [NSString stringWithFormat: @"Listening on port %i",listener.port];
74 - (void) listener: (TCPListener*)listener failedToOpen: (NSError*)error
76 label.text = [NSString stringWithFormat: @"Failed to open listener on port %i: %@",
80 - (void) listener: (TCPListener*)listener didAcceptConnection: (TCPConnection*)connection
82 label.text = [NSString stringWithFormat: @"Accepted connection from %@",
84 connection.delegate = self;
87 - (void) connection: (TCPConnection*)connection failedToOpen: (NSError*)error
89 label.text = [NSString stringWithFormat: @"Failed to open connection from %@: %@",
90 connection.address,error];
93 - (void) connection: (BLIPConnection*)connection receivedRequest: (BLIPRequest*)request
95 NSString *message = [[NSString alloc] initWithData: request.body encoding: NSUTF8StringEncoding];
96 label.text = [NSString stringWithFormat: @"Echoed:\nā%@ā",message];
97 [request respondWithData: request.body contentType: request.contentType];
101 - (void) connectionDidClose: (TCPConnection*)connection;
103 label.text = [NSString stringWithFormat: @"Connection closed from %@",