Added / chg tests
[systematiki.git] / Test / gtk-net-test-2.py
blobc2d6381621758196ae78404c3703dca781a477d7
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
4 import sys
5 sys.path.insert(0, "..")
7 from Systematiki.Net.GObjectProtocol import *
8 from Systematiki.Net.BlockingProtocol import _dbg as deco
11 @deco
12 def unknown(*a, **kw):
13 return False
15 @deco
16 def setup_socket():
17 p = Protocol()
18 p.listen(("localhost", 5000))
19 p.accept(unknown)
21 @deco
22 def add_in_watch(sock2):
23 gobject.io_add_watch(sock2, gobject.IO_IN, data_ready)
25 @deco
26 def data_ready(sock2, cond):
27 data = sock2.recv(BUFLEN)
28 print "%r" % data
29 if data == "":
30 # sock2.close() # This leads to 99% CPU usage!
31 return False
32 if data == "quit\n":
33 sock2.close()
34 mainloop_quit()
35 return False
36 add_in_watch(sock2)
37 return False
39 @deco
40 def setup_mainloop():
41 global mainloop
42 mainloop = gobject.MainLoop()
43 mainloop.run()
45 @deco
46 def mainloop_quit():
47 global mainloop
48 mainloop.quit()
50 @deco
51 def main(argv):
52 setup_socket()
53 setup_mainloop()
54 return 0
56 if __name__ == "__main__":
57 import sys
58 sys.exit(main(sys.argv))