New release (and URL)
[pytipc.git] / examples / stream.py
blob50cea6b5a52f4ad6a6cac27b437bcf2e37739809
1 #!/usr/bin/env python
3 import sys
4 import socket
5 import tipc
6 import cs
8 srvaddr = (tipc.TIPC_ADDR_NAME, 2000, 10, 0)
10 def srv():
11 fd = tipc.socket(socket.SOCK_STREAM)
12 fd.bind(srvaddr)
13 print 'server started, addr:', fd.getsockname()
15 fd.listen(5)
16 conn, addr = fd.accept()
17 print 'connected', addr
19 buf = conn.recv(1024)
20 while buf != "EXIT":
21 print 'srv:', buf
22 buf = conn.recv(1024)
23 print 'srv exit'
25 def cli():
26 print 'waiting'
27 evt = tipc.wait_for(srvaddr, timeout = 500)
28 if not evt or evt[0] == tipc.TIPC_SUBSCR_TIMEOUT:
29 print 'timeout'
30 return
31 print 'server up', evt
33 fd = tipc.socket(socket.SOCK_STREAM)
34 print 'cli ready, addr:', fd.getsockname()
35 fd.connect(srvaddr)
37 l = sys.stdin.readline()
38 while l:
39 fd.send(l.strip())
40 l = sys.stdin.readline()
41 fd.send('EXIT')
42 print 'cli exit'
45 cs.run(srv, cli)