It DOES seem like only when the connection socket is closed via conn.close() that the data is flushed and the 'waiting' ends. So with the earlier suggestion that I open one file-obj for reading and one for writing, I still cannot acheive two-way communication because I need to close the connection for it to actually occur completely!<br>
<br>My client waits after the "done sending" line indefinitely. Weird.<br><br>A<br><br><div class="gmail_quote">On Mon, Mar 1, 2010 at 16:35, Arjun Chennu <span dir="ltr"><<a href="mailto:arjun.chennu@gmail.com">arjun.chennu@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Thanks for the feedback.<br><br>Opening a separate file-obj for writing and for reading is just what I've been trying, but I don't seem to get it to work. I'm new to python and I'm not sure if I'm missing the intricacy of some command. Please help:<br>
<br>Here is my server snippet:<div class="im"><br><br> (conn, addr) = sock1.accept() # connected socket<br> print 'Client (localhost) port: ', addr[1]<br> <br></div> cf = conn.makefile('r',0) # file obj for reading<div class="im">
<br>
lf = open('ccs.txt','w')<br> <br></div> for linenum, line in enumerate(cf): # iterate over socket lines <br> lf.write(line) <br>
#sys.stdout.write(line)<br>
print len(line)<br> <br> cf.close()<br> <br> stat = 'wrote %s lines to file.\n' %(linenum+1)<br> cff = conn.makefile('w',0) # file obj for writing<br>
cff.writelines(stat) # cff.write(stat) does not work either!!<br> cff.close()<br> <br> lf.close()<br> conn.close()<br> print stat, "DONE!"<br>
<br>And here is the client that I have for it: (sfp is the local file object i read from)<div class="im"><br><br> for line in sfp.readlines():<br> cf.write(line)<br> print len(line)<br><br></div>
print 'done sending'<br>
cf.close() #writing ends here<br> <br> cff = s.makefile('r',0) # file obj for writing <br> for line in cff.readlines():<br> print line<br> <br> cff.close()<br>
<br> sfp.close()<br> s.close()<br><br>The execution sends all the lines (and prints out the len(line) ) and then stays waiting. THen when I manually terminate the client script, the server script happily types the "DONE!" output.<br>
<br>Where is this protocol hanging up? Help much appreciated, with a small explanation.<br><br>Cheers,<br><font color="#888888">Arjun</font><div><div></div><br></div></blockquote></div><br>