Instance Method

acceptConnectionInBackgroundAndNotify

Accepts a socket connection (for stream-type sockets only) in the background and creates a file handle for the “near” (client) end of the communications channel.

Declaration

- (void)acceptConnectionInBackgroundAndNotify;

Discussion

This method asynchronously creates a file handle for the other end of the socket connection and returns that object by posting a NSFileHandleConnectionAcceptedNotification notification in the current thread. The notification includes a userInfo dictionary with the created NSFileHandle object, which is accessible using the NSFileHandleNotificationFileHandleItem key.

You must call this method from a thread that has an active run loop.

Special Considerations

The receiver must be created by an initWithFileDescriptor: message that takes as an argument a stream-type socket created by the appropriate system routine, and that is being listened on. In other words, you must bind() the socket, and ensure that the socket has a connection backlog defined by listen().

The object that will write data to the returned file handle must add itself as an observer of NSFileHandleConnectionAcceptedNotification.

Note that this method does not continue to listen for connection requests after it posts NSFileHandleConnectionAcceptedNotification. If you want to keep getting notified, you need to call acceptConnectionInBackgroundAndNotify again in your observer method.

See Also

Communicating Asynchronously

- acceptConnectionInBackgroundAndNotifyForModes:

Accepts a socket connection (for stream-type sockets only) in the background and creates a file handle for the “near” (client) end of the communications channel.

- readInBackgroundAndNotify

Reads from the file or communications channel in the background and posts a notification when finished.

- readInBackgroundAndNotifyForModes:

Reads from the file or communications channel in the background and posts a notification when finished.

- readToEndOfFileInBackgroundAndNotify

Reads to the end of file from the file or communications channel in the background and posts a notification when finished.

- readToEndOfFileInBackgroundAndNotifyForModes:

Reads to the end of file from the file or communications channel in the background and posts a notification when finished.

- waitForDataInBackgroundAndNotify

Asynchronously checks to see if data is available.

- waitForDataInBackgroundAndNotifyForModes:

Asynchronously checks to see if data is available.