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
func acceptConnectionInBackgroundAndNotify()Discussion
This method asynchronously creates a file handle for the other end of the socket connection and returns that object by posting a NSFileHandleConnectionAccepted 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 init(fileDescriptor:) 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 NSFileHandleConnectionAccepted.
Note that this method does not continue to listen for connection requests after it posts NSFileHandleConnectionAccepted. If you want to keep getting notified, you need to call acceptConnectionInBackgroundAndNotify() again in your observer method.