Thanks for this answer. Client do: size1, passed1 = envoyer(conn, 50) size2, passed2 = envoyer(conn, int(size1/passed1)) size3, passed3 = recevoir(conn) size4, passed4 = recevoir(conn) print size2/passed2 print size4/passed4
Server do: recevoir(conn) recevoir(conn) size1, passed1 = envoyer(conn, 50) size2, passed2 = envoyer(conn, int(size1/passed1)) This failed when client do its second 'envoyer' and server sees it still as first 'recevoir'. Why ? I tried conn.shutdown(socket.SHUT_WR) to show first sending is terminated but I naturally got a "broken pipe" for the second sending so how can I resolve this problem ? Putting a time.sleep() in the client is ineffective ... Any idea ? Kent Johnson a écrit : > le dahut wrote: > >>Hi, >>I try to send some data across a network (between 400KB and 10MB) like >>this : >>def envoyer(conn, mysize): >> print mysize,' KB sent' >> data = '1'*1024 >> data_end = data[:-5]+'#####' >> data = data*(mysize-1) >> begining = time.time() >> conn.send(data) >> conn.send(data_end) >> passed = time.time() - begining >> return passed, size >> > > > socket.send() may not send all the data - it returns a count telling you > what it actually did. Use socket.sendall() or put your call to send() in > a loop. > > >>and receive it like this : >> >>def recevoir(conn): >> data='' >> while 1: >> tmpdata = conn.recv(8192) >> data += tmpdata >> if '#####' in data: >> print 'END OF DATA' >> break >> print len(data)/1024, ' KB received' >> return passed, int(data[-15:-5])/1024 > > > socket.recv() will return an empty string when there is no more data - I > would look for that instead of your marker, it is more general. Instead of > if '#####' in data: > you can say > if data == '': > or just > if not data: > > >>But I don't receive as much data that I sent ... does someone know why ? >>If I want to send the same data back to the client, do I have to destroy >>and recreate the socket ? > > > If this doesn't fix it, maybe an example of the lost data would help. > > Kent > -- http://mail.python.org/mailman/listinfo/python-list