bug fixes and improvements to new bonjour classes and tcplistener, also added a static library target
5 // Created by Jens Alfke on 5/10/08.
6 // Copyright 2008 Jens Alfke. All rights reserved.
9 #import "TCPConnection.h"
10 #import "TCPListener.h"
11 @class BLIPRequest, BLIPResponse, BLIPDispatcher;
12 @protocol BLIPConnectionDelegate;
15 /** Represents a connection to a peer, using the <a href=".#blipdesc">BLIP</a> protocol over a TCP socket.
16 Outgoing connections are made simply by instantiating a BLIPConnection via -initToAddress:.
17 Incoming connections are usually set up by a BLIPListener and passed to the listener's
19 Most of the API is inherited from TCPConnection. */
20 @interface BLIPConnection : TCPConnection
23 BLIPDispatcher *_dispatcher;
27 /** The delegate object that will be called when the connection opens, closes or receives messages. */
28 @property (assign) id<BLIPConnectionDelegate> delegate;
30 /** The connection's request dispatcher. By default it's not configured to do anything; but you
31 can add rules to the dispatcher to call specific target methods based on properties of the
34 Requests that aren't handled by the dispatcher (i.e. all of them, by default) will be
35 passed to the delegate's connection:receivedRequest: method; or if there's no delegate,
36 a generic error response will be returned. */
37 @property (readonly) BLIPDispatcher *dispatcher;
39 /** Creates a new, empty outgoing request.
40 You should add properties and/or body data to the request, before sending it by
41 calling its -send method. */
42 - (BLIPRequest*) request;
44 /** Creates a new outgoing request.
45 The body or properties may be nil; you can add additional data or properties by calling
46 methods on the request itself, before sending it by calling its -send method. */
47 - (BLIPRequest*) requestWithBody: (NSData*)body
48 properties: (NSDictionary*)properies;
50 /** Sends a request over this connection.
51 (Actually, it queues it to be sent; this method always returns immediately.)
52 Call this instead of calling -send on the request itself, if the request was created with
53 +[BLIPRequest requestWithBody:] and hasn't yet been assigned to any connection.
54 This method will assign it to this connection before sending it.
55 The request's matching response object will be returned, or nil if the request couldn't be sent. */
56 - (BLIPResponse*) sendRequest: (BLIPRequest*)request;
61 /** The delegate messages that BLIPConnection will send,
62 in addition to the ones inherited from TCPConnectionDelegate.
63 All methods are optional. */
64 @protocol BLIPConnectionDelegate <TCPConnectionDelegate>
67 /** Called when a BLIPRequest is received from the peer, if there is no BLIPDispatcher
69 The delegate should get the request's response object, fill in its data and properties
70 or error property, and send it.
71 If it doesn't explicitly send a response, a default empty one will be sent;
72 to prevent this, call -deferResponse on the request if you want to send a response later. */
73 - (void) connection: (BLIPConnection*)connection receivedRequest: (BLIPRequest*)request;
75 /** Called when a BLIPResponse (to one of your requests) is received from the peer.
76 This is called <i>after</i> the response object's onComplete target, if any, is invoked.*/
77 - (void) connection: (BLIPConnection*)connection receivedResponse: (BLIPResponse*)response;
79 /** Called when the peer wants to close the connection. Return YES to allow, NO to prevent. */
80 - (BOOL) connectionReceivedCloseRequest: (BLIPConnection*)connection;
82 /** Called if the peer refuses a close request.
83 The typical error is kBLIPError_Forbidden. */
84 - (void) connection: (BLIPConnection*)connection closeRequestFailedWithError: (NSError*)error;
90 /** A "server" that listens on a TCP socket for incoming <a href=".#blipdesc">BLIP</a> connections and creates
91 BLIPConnection instances to handle them.
92 Most of the API is inherited from TCPListener. */
93 @interface BLIPListener : TCPListener
95 BLIPDispatcher *_dispatcher;
98 /** The default request dispatcher that will be inherited by all BLIPConnections opened by this
100 If a connection's own dispatcher doesn't have a rule to match a message, this inherited
101 dispatcher will be checked next. Only if it fails too will the delegate be called. */
102 @property (readonly) BLIPDispatcher *dispatcher;