-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhello_socket.py
More file actions
51 lines (40 loc) · 1.19 KB
/
Copy pathhello_socket.py
File metadata and controls
51 lines (40 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# PORT=8855
import socket
import json
import time
import numpy as np
def read_lines_from_socket(sock):
buffer_size = 1024 # You can adjust the buffer size according to your needs
data = b""
while True:
chunk = sock.recv(buffer_size)
if not chunk:
break
data += chunk
while b'\n' in data:
line, data = data.split(b'\n', 1)
yield line.decode('utf-8')
# Replace 'SERVER_IP' and 'PORT' with the actual IP and port of your server
server_ip = '10.0.0.12'
port = 8855
# Create a socket
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Connect to the server
client_socket.connect((server_ip, port))
max_dt=0
last_time=time.time()
dts=[]
for line in read_lines_from_socket(client_socket):
if line[-2]==',':
line=line[:-2]+line[-1]
line = json.loads(line)
# print("Received:", line)
ct=time.time()
dt=ct-last_time
last_time=ct
dts.append(dt)
if dt>max_dt:
max_dt=dt
print(f'fps={1/dt:0.2f} min fps={1/max_dt:0.2f} mean fps={1/np.mean(dts):0.2f} dt={np.mean(dts):0.2f}/{np.max(dts):0.2f}')
# Close the socket when done
client_socket.close()