#-*- conding:UTF-8 -*-
import asyncore , socket

class HttpClient(asyncore.dispatcher):
    def __init__(self ,host ,path):
        asyncore.dispatcher.__init__(self)
        self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
        self.connect((host,8080))
        self.buffer = 'TRANCE %s/ HTTP/1.1\r\nHost:%s\r\n\r\n'%(path ,path)
        print self.buffer
        
    def handle_connect(self):
        pass

    def handle_close(self):
        self.close()
        print 'close connect to server.'
        
    def handle_read(self):
        print self.recv(1024)

    def handle_write(self):
        print 'write data to server'
        send = self.send(self.buffer)
        self.buffer = self.buffer[send:]
        
    def writable(self):
        return (len(self.buffer) > 0)
    
if __name__ == '__main__':
    c = HttpClient('10.99.60.202' ,'www.baidu.com')
    asyncore.loop()
