asyncore: handle_accept() question?

Ng Pheng Siong ngps at netmemetic.com
Wed Aug 27 21:36:01 EDT 2003


According to Chris <chrisahlers at yahoo.com>:
> class connection(asyncore.dispatcher):
> 	def __init__(self, host = None, port = None, sock = None):
> 		asyncore.dispatcher.__init__(self)  
> 		self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
> 		self.set_reuse_addr() # needed?
> 
> 		if host and port: self.connect((host, port))
> 		if sock is not None:
> 			print 'setting socket'
> 			self.set_socket(sock)

It's been a while since I did asyncore stuff, so I may be off-base. From
asyncore.py:

    def create_socket (self, family, type):
        self.family_and_type = family, type
        self.socket = socket.socket (family, type)
        [...]

    def set_socket (self, sock, map=None):
        self.socket = sock
        [...]

Your code calls self.create_socket, which binds self.socket to a newly
created socket, then it calls self.set_socket(sock), which binds
self.socket to your accepted socket.


-- 
Ng Pheng Siong <ngps at netmemetic.com> 

http://firewall.rulemaker.net  -+- Manage Your Firewall Rulebase Changes
http://www.post1.com/home/ngps -+- Open Source Python Crypto & SSL




More information about the Python-list mailing list