Added #imports of utility headers, so source files will compile without requiring a custom prefix (MYUtilities.pch.)
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 @property (readonly) BLIPDispatcher *dispatcher;
30 /** Creates an outgoing request, with no properties.
32 To send it, call -send. */
33 - (BLIPRequest*) requestWithBody: (NSData*)body;
35 /** Creates an outgoing request.
36 The body or properties may be nil.
37 To send it, call -send. */
38 - (BLIPRequest*) requestWithBody: (NSData*)body
39 properties: (NSDictionary*)properies;
41 /** Sends a request over this connection.
42 (Actually, it queues it to be sent; this method always returns immediately.)
43 Call this instead of calling -send on the request itself, if the request was created with
44 +[BLIPRequest requestWithBody:] and hasn't yet been assigned to any connection.
45 This method will assign it to this connection before sending it.
46 The request's matching response object will be returned, or nil if the request couldn't be sent. */
47 - (BLIPResponse*) sendRequest: (BLIPRequest*)request;
52 /** The delegate messages that BLIPConnection will send,
53 in addition to the ones inherited from TCPConnectionDelegate. */
54 @protocol BLIPConnectionDelegate <TCPConnectionDelegate>
56 /** Called when a BLIPRequest is received from the peer, if there is no BLIPDispatcher
58 The delegate should get the request's response object, fill in its data and properties
59 or error property, and send it.
60 If it doesn't explicitly send a response, a default empty one will be sent;
61 to prevent this, call -deferResponse on the request if you want to send a response later. */
62 - (void) connection: (BLIPConnection*)connection receivedRequest: (BLIPRequest*)request;
65 /** Called when a BLIPResponse (to one of your requests) is received from the peer.
66 This is called <i>after</i> the response object's onComplete target, if any, is invoked. */
67 - (void) connection: (BLIPConnection*)connection receivedResponse: (BLIPResponse*)response;
73 /** A "server" that listens on a TCP socket for incoming BLIP connections and creates
74 BLIPConnection instances to handle them.
75 Most of the API is inherited from TCPListener. */
76 @interface BLIPListener : TCPListener
78 BLIPDispatcher *_dispatcher;
81 @property (readonly) BLIPDispatcher *dispatcher;