[Tutor] socket and lost data

Alan Gauld alan.gauld at freenet.co.uk
Fri Jan 27 16:09:22 CET 2006


I'm a wee bit confused.

> def envoyer(conn, mysize):
>     print mysize,' KB sent

This doesn't seem to be true from the code.

>     data = '1'*1024
>     data_end = data[:-5]+'#####'
>     data = data*(mysize-1)

So data is mysize-1 KB, but you printed mysize KB?

>     begining = time.time()
>     conn.send(data)
>     conn.send(data_end)
>     passed = time.time() - begining

it migfht be more useful to print the siuze here and work out what you 
really sent:

print 'sent: ',len(data) + len(data_end), 'bytes'

>     return passed, size

where is size defined?

> 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
>
> But I don't receive as much data that I sent ... does someone know why ?

if you are going by your print statements they will not match.

> If I want to send the same data back to the client, do I have to destroy 
> and recreate the socket ?

There is nothing to stop you having two sockets, one in each direction.

Alan G



More information about the Tutor mailing list