import asyncore socket class client asyncore dispatcher def __init__ s

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import asyncore, socket
class client(asyncore.dispatcher):
def __init__(self, host, port):
asyncore.dispatcher.__init__(self)
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.connect((host, port))
self.port = port
def handle_connect(self):
print self.port, "connected"
def handle_close(self):
self.close()
def handle_error(self):
print self.port, "error"
def handle_read(self):
print self.recv(1)
def writable(self):
return 1
def handle_write(self):
self.close()
client('localhost', 9299)
asyncore.loop()