I am trying to measure the speed of file transfer through sockets in python. I set up measurements on both ends (sending and receiving side) and get somewhat different results (i.e. 16 vs 17 Mbps for a 1MB file transferred via ad-hoc wifi). My question is whether this kind of difference is something I should expect, given the measurement setup following. This is all running on two Raspberry Pi models 2 B.
sender:
import socket as s
sock = s.socket(s.AF_INET, s.SOCK_STREAM)
sock.connect((addr,5000))
start = t.time()
sock.sendall(data)
finish = t.time()
receiver:
import socket as s
sock = s.socket(s.AF_INET, s.SOCK_STREAM)
sock.setsockopt(s.SOL_SOCKET, s.SO_REUSEADDR, 1)
sock.bind(("", 5000))
sock.listen(1)
conn, addr = sock.accept()
pack = []
start = t.time()
while True:
piece = conn.recv(8192)
if not piece:
finish = t.time()
break
pack.append(piece.decode())
Also very welcome, any other transfer speed measurements advices, if there is any way to do this better.
I think the speedtest-cli what are you locking for. Also, there is a good article about it. It seems that Raspberry Pi supported.
Matt Martz has created a Python project called speedtest-cli which allows you to do a basic upload/download measurement using SpeedNet’s infrastructure. It works fine on the Pi and is really easy to try out on the command line.
If you want make your own script, anyway speedtest_cli.py
good place to start.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With