|
From: | Ivan Vučica |
Subject: | Re: "Modern" server socket programming? |
Date: | Tue, 8 Jan 2013 22:33:02 +0100 |
8. 1. 2013., u 18:19, Marcus Müller <address@hidden> je napisao:
David is, if I understand correctly, referring to using methods such as -[NSFileHandle acceptConnectionInBackgroundAndNotify] after creating the file handle with -[NSFileHandle initWithFileDescriptor:closeOnDealloc:]. Once one of these observation methods is used, the method actually schedules observing for file events on the runloop, and upon noticing an event that you scheduled observing for, sends a notification through NSNotificationCenter. For example, having created a socket... NSSocketPort* serverSock = [[NSSocketPort alloc] initWithTCPPort: 1234]; ...wrap its file handle into a file handle... socketHandle = [[NSFileHandle alloc] initWithFileDescriptor: [serverSock socket] closeOnDealloc: NO]; ...begin observing for notifications... [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(newConnection:) name: NSFileHandleConnectionAcceptedNotification object: socketHandle]; ... and finally schedule observing the event (and dispatching the notifications): [socketHandle acceptConnectionInBackgroundAndNotify]; Taken from this (broken) piece of code: The relevant piece of code that I described does not seem broken, and the general idea seems to be sound. If the relevant code is fundamentally broken, someone please shame me. I didn't use this API before. Looking at NSFileHandle documentation will probably be the best course of action.
No, David is just talking about the fact that, if you already have access to a file handle for a socket (that is, the return value of the socket() call) in whatever underlying library you use or if you use the BSD sockets directly, you can use NSFileHandle quite easily.
Via -[NSFileHandle acceptConnectionInBackgroundAndNotify] and other similar ...InBackgroundAndNotify methods. |
[Prev in Thread] | Current Thread | [Next in Thread] |