newbie asyncore question on win9x

howardlightstone@s... howardlightstone@s...
Fri, 29 Sep 2000 17:15:39 -0000


I seem to be unable to get a simple test of asyncore to 'work'. I 
tried just a simple server/client pair (see below) but I never get a 
handle_recv event. I can see the connection being made between the 
slave accept port (some small port number like 13xx) and the master 
port (50007). After the master 'sends' data, the connection goes 
silently away. What am I not doing?

Thanks

-------------------------------------------------------------
'Slave' server

import string
import socket
import asyncore

HOST = 'localhost' # Symbolic name meaning the local 
host
PORT = 50007 # Arbitrary non-privileged server

class goer(asyncore.dispatcher_with_send):
def __init__(self, sock,conn,addr,reader=None):
asyncore.dispatcher.__init__ (self,conn)
self.create_socket (socket.AF_INET, socket.SOCK_STREAM)
self.set_reuse_addr()
self.bind(addr)
self.listen(5)
self.reader=reader
print 'goer=',sock,conn,addr

def handle_read(self):
print 'handle read'
if self.reader != None:
self.reader(self)

class checker(asyncore.dispatcher):
def __init__(self, port=PORT):
self.port = port
asyncore.dispatcher.__init__ (self)
self.create_socket (socket.AF_INET, socket.SOCK_STREAM)
self.set_reuse_addr()
self.bind((HOST, port))
self.listen(5)
self.readin=None
print 'checker init',self,self.socket

def handle_accept(self):
print 'handle accept'
conn,addr=self.accept()
g=goer(self,conn,addr,self.readin)
print self,self.socket,g

def read_me(asock):
" reads from async socket"
global endit
print 'in read_me'
data=asock.recv
print data
#endit=process(data)

s=checker()
s.readin=read_me
endit=0
counter=0
while endit == 0:
asyncore.poll()
counter=counter+1
cv='%6d' % counter
#show_whats_up
asyncore.close_all()


===========================================
'master' client

from socket import *
HOST = 'localhost' # The remote host
PORT = 50007 # The same port as used by the server
s = socket(AF_INET, SOCK_STREAM)
s.connect(HOST, PORT)

while 1:
x=raw_input('Command: ')
if len(x):
s.send(x)
if x[0] == 'x':
break


s.close()