[Pyobjc-dev] Question about Python sockets and NSFileDescriptors
Brought to you by:
ronaldoussoren
From: Jim C. <cl...@cs...> - 2004-02-20 01:10:27
|
Hello, I've narrowed my problem down a bit more. I'm wrapping a python socket in an NSFileDescriptor and then registering to receive ConnectionAccepted notifications. When I run my code listed below I just get an infinite number of notifications. Can anyone see any errors in my code or explain why I might be getting some many connection notices? Thanks again, Jim import socket from Foundation import * from AppKit import * from PyObjCTools import NibClassBuilder, AppHelper NibClassBuilder.extractClasses("MainMenu") class TestServer(NibClassBuilder.AutoBaseClass): def awakeFromNib(self): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.bind((socket.gethostname(), 0)) sock.listen(1) # Wrap the socket in an NSFileHandle using fileno() to get the # file descriptor for the socket object listeningSocket = NSFileHandle.alloc().initWithFileDescriptor_(sock.fileno()) # Register that we want to be informed of connection notifications NSNotificationCenter.defaultCenter().addObserver_selector_name_object_(s elf, "handleConnectionNotification:", NSFileHandleConnectionAcceptedNotification, listeningSocket) listeningSocket.acceptConnectionInBackgroundAndNotify() def handleConnectionNotification_(self, aNotification): print "Got Connection" aNotification.object().acceptConnectionInBackgroundAndNotify() if __name__ == "__main__": AppHelper.runEventLoop() |