2 import asyncore
, socket
4 class Node(asyncore
.dispatcher
):
5 def __init__(self
, host
, coords
):
7 asyncore
.dispatcher
.__init
__(self
)
8 self
.create_socket(socket
.AF_INET
, socket
.SOCK_STREAM
)
9 self
.socket
.setblocking(1)
11 self
.socket
.setblocking(0)
13 def handle_connect(self
):
14 self
.send("%i:%i\r\n" % self
.coords
)
15 data
= self
.recv(4096)
16 if data
!= "okay\r\n":
18 self
.writable
= lambda : False
20 def handle_read(self
):
21 data
= self
.recv(4096)
24 elif data
== 'off\r\n':
27 def handle_close(self
):
30 def process(self
, val
):
31 print self
.coords
, val
34 if __name__
== '__main__':
43 nodes
.append(Node(host
, (int(x
), int(y
))))
47 nodes
.append(Node(host
, (x
, y
)))