Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Measuring wifi file-transfer speed in python

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.

like image 744
Milan C. Avatar asked Nov 09 '22 14:11

Milan C.


1 Answers

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.

like image 80
fedorshishi Avatar answered Nov 14 '22 21:11

fedorshishi