STAR
Cal STAR ā firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
test_udp_receive.py
Go to the documentation of this file.
1
#!/usr/bin/env python3
2
"""Simple UDP receiver to test if packets are arriving on port 5007"""
3
4
import
socket
5
import
sys
6
7
8
def
main
():
9
port = 5007
10
if
len(sys.argv) > 1:
11
port = int(sys.argv[1])
12
13
print(f
"š” Listening for UDP packets on port {port}..."
)
14
print(
"Press Ctrl+C to stop\n"
)
15
16
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
17
sock.bind((
"0.0.0.0"
, port))
18
sock.settimeout(1.0)
# 1 second timeout
19
20
packet_count = 0
21
try
:
22
while
True
:
23
try
:
24
data, addr = sock.recvfrom(4096)
25
packet_count += 1
26
print(
27
f
"[{packet_count}] Received {len(data)} bytes from {addr[0]}:{addr[1]}"
28
)
29
if
packet_count <= 3:
30
print(
31
f
" First 16 bytes: {' '.join(f'{b:02x}' for b in data[:16])}"
32
)
33
except
socket.timeout:
34
if
packet_count == 0:
35
print(
"."
, end=
""
, flush=
True
)
36
continue
37
except
KeyboardInterrupt:
38
print(f
"\n\nā Received {packet_count} packets total"
)
39
40
sock.close()
41
42
43
if
__name__ ==
"__main__"
:
44
main
()
test_udp_receive.main
main()
Definition
test_udp_receive.py:8
daq-server
test
test_udp_receive.py
Generated by
1.15.0