Debian Codegraph @

protolib/examples/pipeExample.py

raw
1
2 import protokit
3 import sys
4 import time
5 # Usage: python pipeExample {send | recv} <pipeName>
6
7
8 # Take your pick of which pipe type you want to try
9 # (Note that "STREAM" is currently limited to a single
10 # accepted connection)
11
12 #pipeType = "MESSAGE"
13 pipeType = "STREAM"
14
15 mode = sys.argv[1]
16 pipeName = sys.argv[2]
17
18 protoPipe = protokit.Pipe(pipeType)
19
20 if "recv" == mode:
21 protoPipe.Listen(pipeName)
22 if "STREAM" == pipeType:
23 protoPipe.Accept()
24 while True:
25 buf = protoPipe.Recv(8192)
26 print buf
27 else:
28 protoPipe.Connect(pipeName)
29 count = 0
30 while True:
31 count += 1
32 protoPipe.Send("Hello, ProtoPipe %s (%d) ..." % (pipeName, count))
33 time.sleep(1.0)