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.
- iOS 2.0+
- macOS 10.0+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
This method asynchronously creates a file handle for the other end of the socket connection and returns that object by posting a
NSFile notification in the current thread. The notification includes a
user dictionary with the created
NSFile object, which is accessible using the
You must call this method from a thread that has an active run loop.
The receiver must be created by an
init(file 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
The object that will write data to the returned file handle must add itself as an observer of
Note that this method does not continue to listen for connection requests after it posts
NSFile. If you want to keep getting notified, you need to call
accept again in your observer method.