aeruder@ksu.edu
)Version: Revision 1
Date: July 7, 2005
How to use netclasses synchronously.
Copyright: (C) Andrew Ruder
While netclasses is primarily for asynchronous connections, it can somewhat easily be used for synchronous connections as well.
This is primarily done by directly calling the -[id<NetTransport> writeData:] and -[id<NetTransport> readData:] methods on the appropriate transport. This must be done while the object is not being handled by NetApplication .
The first thing to worry about is that the object is not being handled asynchronously by NetApplication . To ensure that this is the case, -[NetApplication disconnectObject:] should be called with the object we are interested in as the argument. This will remove it from the netclasses runloop. At this point, the object is ready to be written to and read from synchronously.
After disabling asynchronous mode, you can easily write any data you want to the transport using the -[id<NetTransport> writeData:] method with a NSData as the argument. However, none of the data is actually written out. To force the write out of the data, pass a 'nil' argument to -[id<NetTransport> writeData:] . To see if there is more data, use the -[id<NetTransport> isDoneWriting] method on the transport.
After disabling asynchronous mode, you can easily read data from the transport using the -[id<NetTransport> readData:] method. This method takes a single argument of the maximum number of bytes to read. Passing 0 will cause as much data as is available to be read.