asyncore: handle_accept() question?
chrisahlers at yahoo.com
Wed Aug 27 23:50:57 CEST 2003
Here's the idea:
I have a listen_server listening to a specific port. A connection
object connects to it remotely, and then the communication begins.
Once connected, I would like to have the server act no differently
than the client (i.e. use the connection class to handle the
connection). This way rather than having a typical server and
client(producer/consumer) I have two peers.
def __init__(self, port): ### Basic Server Stuff ###
conn, addr = self.accept()
print conn.fileno() ## this always prints a number
print 'connection accepted' ## this always prints
newcon = connection(sock=conn) ## error happens here
def __init__(self, host = None, port = None, sock = None):
self.set_reuse_addr() # needed?
if host and port: self.connect((host, port))
if sock is not None:
print 'setting socket'
data = self.recv(4096)
print 'closed connection'
Here is my output:
Traceback (most recent call last):
File "test.py", line 66, in ?
File "/usr/lib/python2.2/asyncore.py", line 206, in loop
poll_fun (timeout, map)
File "/usr/lib/python2.2/asyncore.py", line 83, in poll
r,w,e = select.select (r,w,e, timeout)
select.error: (9, 'Bad file descriptor')
My basic problem is that I don't know any other way to 'hand off' the
incoming connection - if there is a better way to do this please let
me know. conn.fileno() appears to work, and I don't understand why
this error comes up.
More information about the Python-list