J'écris un code python pour trouver le débit entre le serveur et le client. Il est basé sur la fonctionnalité speedtest.net où j'envoie un fichier fictif pour calculer la vitesse. Le problème auquel je fais face est une sortie de débit peu fiable. J'apprécierai vos suggestions sur la même chose. Voici le code.Valeur de débit incorrecte en python
server.py
import socket
import os
port = 60000
s = socket.socket()
host = socket.gethostname()
s.bind((host, port))
s.listen(5)
print 'Server listening....'
while True:
conn, addr = s.accept()
print 'Got connection from', addr
data = conn.recv(1024)
print('Server received', repr(data))
filename='akki.txt'
b = os.path.getsize(filename)
f = open(filename,'rb')
l = f.read(b)
while (l):
conn.send(l)
l = f.read(b)
f.close()
print('Done sending')
conn.send('Thank you for connecting')
conn.close()
Client.py
import socket
import time
import os
s = socket.socket()
host = socket.gethostname()
port = 60000
t1 = time.time()
s.connect((host, port))
s.send("Hello server!")
with open('received_file', 'wb') as f:
print 'file opened'
t2 = time.time()
while True:
data = s.recv(1024)
if not data:
break
f.write(data)
t3 = time.time()
print data
print 'Total:', t3 - t1
print 'Throughput:', round((1024.0 * 0.001)/(t3 - t1), 3),
print 'K/sec.'
f.close()
print('Successfully received the file')
s.close()
print('connection closed')
sortie lors de l'envoi akki.txt
Output Server
Server listening....
Got connection from ('10.143.47.165', 60902)
('Server received', "'Hello server!'")
Done sending
Sortie client fichier ouvert
Raw timers: 1503350568.11 1503350568.11 1503350568.11
Total: 0.00499987602234
**Throughput: 204.805 K/sec.**
Successfully received the file
connection closed
sortie pour ak.zip (qui est plus grand fichier)
fichier de sortie client ouvert
Total: 0.0499999523163
**Throughput: 20.48 K/sec.**
Successfully received the file
connection closed