#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Posts
    9
    Rep Power
    0

    Can't get asyncore to work


    I'm running python 2.4 on Win2000. When I run the program it connects and sends the message. I can see in Ethereal that the server responds, but I never reach my handle_read function?

    Code:
    import sys
    import socket
    
    import asyncore
    import parse_OP
    
    class OPcom(asyncore.dispatcher):                
    	def __init__(self,HOST,PORT):            
                asyncore.dispatcher.__init__(self)
                self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
                try:
                    self.connect ( (HOST,PORT) )
                except error,msg:
                    print 'Could not connect', error, mesg
                    sys.exit(1)
                self.buffer='' 
                self.r_buffer=[]
                self.message_handler=parse_OP.XML_op('OP_send.xml','OP_rec.xml')
                
                
            def handle_connect(self):
                print 'Handle connect'
                tmp=self.message_handler.get_message('0001','001')
                self.buffer = tmp
    	
    	def handle_read(self):
                print 'I was here'
                data = self.recv(8192)
                print 'Received data',data
                self.r_buffer.append(data)
                        
            def writable(self):
                return (len(self.buffer) > 0)
        
            def handle_write(self):
                print 'sending data'
                sent = self.send(self.buffer)
                self.buffer = self.buffer[sent:]        
                
            def close(self):
                self.close()
      
    
    if __name__ == "__main__": #Executes if this is the file executed (this for test purpose)
        
        
    
        HOST='10.40.24.164'
        PORT=4545
       
        s= OPcom( HOST,PORT )
        
        asyncore.loop()
    Last edited by southstar; December 7th, 2004 at 10:39 AM. Reason: Very bad code

IMN logo majestic logo threadwatch logo seochat tools logo