Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #3727
| From | Dun Peal <dunpealer@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Why doesn't this asyncore.dispatcher.handle_read() get called? |
| Date | 2011-04-20 09:25 -0700 |
| Organization | http://groups.google.com |
| Message-ID | <11c683ce-3687-4a07-9d59-0371ba84562e@e8g2000vbz.googlegroups.com> (permalink) |
Hi,
I'm writing and testing an asyncore-based server. Unfortunately, it
doesn't seem to work. The code below is based on the official docs and
examples, and starts a listening and sending dispatcher, where the
sending dispatcher connects and sends a message to the listener - yet
Handler.handle_read() never gets called, and I'm not sure why. Any
ideas?
Thanks, D.
import asyncore, socket, sys
COMM_PORT = 9345
class Handler(asyncore.dispatcher):
def handle_read(self):
print 'This never prints'
class Listener(asyncore.dispatcher):
def __init__(self, port=COMM_PORT):
asyncore.dispatcher.__init__(self)
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.set_reuse_addr()
self.bind(('', port))
self.listen(5)
def handle_accept(self):
client, addr = self.accept()
print 'This prints.'
return Handler(client)
class Sender(asyncore.dispatcher):
def __init__(self, host):
asyncore.dispatcher.__init__(self)
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.connect( (host, COMM_PORT) )
self.buffer = 'Msg\r\n'
def handle_connect(self):
pass
def writable(self):
return len(self.buffer) > 0
def handle_write(self):
sent = self.send(self.buffer)
self.buffer = self.buffer[sent:]
def test_communication():
from multiprocessing import Process
def listener():
l = Listener()
asyncore.loop(timeout=10, count=1)
lis = Process(target=listener)
lis.start()
def sender():
s = Sender('localhost')
asyncore.loop(timeout=10, count=1)
sen = Process(target=sender)
sen.start()
lis.join()
test_communication()
Back to comp.lang.python | Previous | Next — Next in thread | Find similar
Why doesn't this asyncore.dispatcher.handle_read() get called? Dun Peal <dunpealer@gmail.com> - 2011-04-20 09:25 -0700
Re: Why doesn't this asyncore.dispatcher.handle_read() get called? Jean-Paul Calderone <calderone.jeanpaul@gmail.com> - 2011-04-20 13:01 -0700
Re: Why doesn't this asyncore.dispatcher.handle_read() get called? Dun Peal <dunpealer@gmail.com> - 2011-04-20 14:17 -0700
csiph-web