Duplex communication with pipes - is possible ?
Dara Durum
durumdara at gmail.com
Tue Jun 20 07:59:54 EDT 2006
Hi !
Ahhh !
It's working !
This is the simple client code:
if 'C' in sys.argv:
#sys.stdout=open(r'c:\tpp2client.log','w')
print "clt start"
while 1:
head=sys.stdin.read(4)
print "clt head",[head]
if head.lower()=='quit':
break
dsize=int(head)
if dsize:
data=sys.stdin.read(dsize)
print "clt get data"#,[data]
print "clt end\n"
And the master:
else:
print "MS"
p=subprocess.Popen([r'c:\python24\python.exe','tpp2.py','C'], \
stdin=subprocess.PIPE,stdout=subprocess.PIPE)
print "MSS"
(child_stdout, child_stdin) = (p.stdout, p.stdin)
data=range(1000)
import cPickle
bdata=cPickle.dumps(data,1)
print len(bdata)
import binascii
hdata=binascii.hexlify(bdata)
print len(hdata)
import base64
hdata=base64.encodestring(bdata)
print len(hdata)
child_stdin.write('%04d'%len(hdata))
child_stdin.write(hdata)
child_stdin.write('quit')
#child_stdin.write('quit')
#child_stdin.write('quit\n')
output=child_stdout.readlines()
print [output]
print "MEE"
Now I trying with packet size decreasing. Are PIPE-s can handle the
binary data packets, or I need to convert them with base64 ?
Thanks for your help:
dd
More information about the Python-list
mailing list