mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Update test TCP client.
This commit is contained in:
parent
6a04514887
commit
3c35ae8360
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python
|
||||||
# This file is part of the OpenMV project.
|
# This file is part of the OpenMV project.
|
||||||
#
|
#
|
||||||
# Copyright (c) 2013-2019 Ibrahim Abdelkader <iabdalkader@openmv.io>
|
# Copyright (c) 2013-2019 Ibrahim Abdelkader <iabdalkader@openmv.io>
|
||||||
@ -6,19 +6,35 @@
|
|||||||
#
|
#
|
||||||
# This work is licensed under the MIT license, see the file LICENSE for details.
|
# This work is licensed under the MIT license, see the file LICENSE for details.
|
||||||
#
|
#
|
||||||
# An example sockets client.
|
# An example TCP client for testing WiFi modules.
|
||||||
|
|
||||||
import time
|
import time
|
||||||
import select
|
import select
|
||||||
import socket
|
import socket
|
||||||
ADDR=('192.168.1.101', 8000)
|
|
||||||
|
UPLOAD_LEN = 5*1024
|
||||||
|
DOWNLOAD_LEN = 10*1024
|
||||||
|
ADDR=('192.168.1.103', 8080)
|
||||||
|
|
||||||
|
def recvall(sock, n):
|
||||||
|
# Helper function to recv n bytes or return None if EOF is hit
|
||||||
|
data = bytearray()
|
||||||
|
while len(data) < n:
|
||||||
|
packet = sock.recv(n - len(data))
|
||||||
|
if not packet:
|
||||||
|
return None
|
||||||
|
data.extend(packet)
|
||||||
|
return data
|
||||||
|
|
||||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
s.connect(ADDR)
|
s.connect(ADDR)
|
||||||
time.sleep(0.500)
|
|
||||||
s.send("HelloWorld")
|
upload = 0
|
||||||
time.sleep(0.500)
|
download = 0
|
||||||
print (s.recv(10))
|
while (True):
|
||||||
time.sleep(3)
|
s.sendall(b'0' * UPLOAD_LEN)
|
||||||
print ("closing")
|
buf = recvall(s, DOWNLOAD_LEN)
|
||||||
|
upload += UPLOAD_LEN
|
||||||
|
download += DOWNLOAD_LEN
|
||||||
|
print("Upload: %.3f MBytes Download: %.3f MBytes" %(upload/(1024*1024), download/(1024*1024)))
|
||||||
s.close()
|
s.close()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user