* Added more documentation.
* Minor API changes.
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 BLIP 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
22 BLIPDispatcher *_dispatcher;
25 /** The delegate object that will be called when the connection opens, closes or receives messages. */
26 @property (assign) id<BLIPConnectionDelegate> delegate;
28 /** The connection's request dispatcher. By default it's not configured to do anything; but you
29 can add rules to the dispatcher to call specific target methods based on properties of the
32 Requests that aren't handled by the dispatcher (i.e. all of them, by default) will be
33 passed to the delegate's connection:receivedRequest: method; or if there's no delegate,
34 a generic error response will be returned. */
35 @property (readonly) BLIPDispatcher *dispatcher;
37 /** Creates an outgoing request, with no properties.
39 To send it, call -send. */
40 - (BLIPRequest*) requestWithBody: (NSData*)body;
42 /** Creates an outgoing request.
43 The body or properties may be nil.
44 To send it, call -send. */
45 - (BLIPRequest*) requestWithBody: (NSData*)body
46 properties: (NSDictionary*)properies;
48 /** Sends a request over this connection.
49 (Actually, it queues it to be sent; this method always returns immediately.)
50 Call this instead of calling -send on the request itself, if the request was created with
51 +[BLIPRequest requestWithBody:] and hasn't yet been assigned to any connection.
52 This method will assign it to this connection before sending it.
53 The request's matching response object will be returned, or nil if the request couldn't be sent. */
54 - (BLIPResponse*) sendRequest: (BLIPRequest*)request;
59 /** The delegate messages that BLIPConnection will send,
60 in addition to the ones inherited from TCPConnectionDelegate. */
61 @protocol BLIPConnectionDelegate <TCPConnectionDelegate>
63 /** Called when a BLIPRequest is received from the peer, if there is no BLIPDispatcher
65 The delegate should get the request's response object, fill in its data and properties
66 or error property, and send it.
67 If it doesn't explicitly send a response, a default empty one will be sent;
68 to prevent this, call -deferResponse on the request if you want to send a response later. */
69 - (void) connection: (BLIPConnection*)connection receivedRequest: (BLIPRequest*)request;
72 /** Called when a BLIPResponse (to one of your requests) is received from the peer.
73 This is called <i>after</i> the response object's onComplete target, if any, is invoked.
74 (This method is optional.) */
75 - (void) connection: (BLIPConnection*)connection receivedResponse: (BLIPResponse*)response;
81 /** A "server" that listens on a TCP socket for incoming BLIP connections and creates
82 BLIPConnection instances to handle them.
83 Most of the API is inherited from TCPListener. */
84 @interface BLIPListener : TCPListener
86 BLIPDispatcher *_dispatcher;
89 /** The default request dispatcher that will be inherited by all BLIPConnections opened by this
91 If a connection's own dispatcher doesn't have a rule to match a message, this inherited
92 dispatcher will be checked next. Only if it fails too will the delegate be called. */
93 @property (readonly) BLIPDispatcher *dispatcher;