DTBonjourDataConnection Class Reference
Inherits from | NSObject |
Declared in | DTBonjourDataConnection.h |
Overview
This class represents a data connection, established via file handle or Bonjour NSNetService
It can be used by itself to establish a connection as a client to a remote server. In the context of a DTBonjourServer
there might be any number of live connections. In the server context you should not modify the connection delegate as the connections are owned and maintained by the server.
Tasks
Creating a Data Connection
Connection Lifetime
Sending Objects
Getting Information
-
– isOpen
-
delegate
property -
sendingContentType
property
Properties
delegate
A delegate to be informed about activities of the connection. If the connection is owned by a DTBonjourServer
you should not modify this property.
@property (nonatomic, weak) id<DTBonjourDataConnectionDelegate> delegate
Declared In
DTBonjourDataConnection.h
sendingContentType
The type of how objects are to be encoded for transit. The default is to encode with NSCoding, JSON is also available as an option.
@property (nonatomic, assign) DTBonjourDataConnectionContentType sendingContentType
Discussion
Note: JSON can only encode NSArray
and NSDictionary
root objects.
Declared In
DTBonjourDataConnection.h
Instance Methods
initWithInputStream:outputStream:
Initializes the receiver from the given input and output streams.
- (id)initWithInputStream:(NSInputStream *)inStream outputStream:(NSOutputStream *)outStream
Parameters
- inStream
Input stream for the connection.
- outStream
Output stream for the connection.
Declared In
DTBonjourDataConnection.h
initWithNativeSocketHandle:
Initializes the receiver from a native Posix file handle representing a socket.
- (id)initWithNativeSocketHandle:(CFSocketNativeHandle)nativeSocketHandle
Parameters
- nativeSocketHandle
The native socket handle to create the connection for
Declared In
DTBonjourDataConnection.h
initWithService:
Initialized the receiver from a Bonjour NSNetService
- (id)initWithService:(NSNetService *)service
Parameters
- service
The
NSNetService
to create the connection for
Declared In
DTBonjourDataConnection.h
isOpen
YES
if the connection is open and can be used to send or receive data
- (BOOL)isOpen
Return Value
YES
if the connection is open and can be used to send or receive data
Declared In
DTBonjourDataConnection.h
open
Opens the connection and establishes the input and output streams. Cancels the
opening after a timeout of DTBonjourDataConnectionDefaultTimeout
seconds.
- (BOOL)open
Return Value
YES
if the connection could be established.
Declared In
DTBonjourDataConnection.h
openWithTimeout:
Opens the connection and establishes the input and output streams.
- (BOOL)openWithTimeout:(NSTimeInterval)timeout
Parameters
- timeout
Timeout in seconds after which to cancel the stream opening.
Return Value
YES
if the connection could be established.
Declared In
DTBonjourDataConnection.h
sendObject:error:
Encodes the passed object via the current sendingContentType and adds it to the output stream.
- (BOOL)sendObject:(id)object error:(NSError **)error
Parameters
- object
Can be any object that is supported by the current sending content type.
- error
An option error output parameter
Return Value
YES
if the object was successfully encoded and enqueued for sending
Discussion
Note: The return parameter does not tell if the actual sending has already taken place, only if the object could be encoded and enqueued for sending.
Declared In
DTBonjourDataConnection.h