-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathudp_server.py
More file actions
36 lines (31 loc) · 1.06 KB
/
udp_server.py
File metadata and controls
36 lines (31 loc) · 1.06 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
import sys
import time
from support_loader import espp
# defined out here so that it's only initialized once, not on each callback
start = time.time()
def on_receive_data(data, sender_info):
global start
port = 5555
elapsed = time.time() - start
print(f"[{elapsed:.3f}] Received: '{data}'")
str_data = ''.join(chr(x) for x in data)
print(f" as string: '{str_data}'")
print(f" from: {sender_info.address}:{sender_info.port}")
ret_data = list("Data returned to sender goes here...")
print(f" responding: {len(ret_data)} bytes to {sender_info.address}:{sender_info.port}")
# turn the list of characters into a list of integers
ret_data = [ord(x) for x in ret_data]
return ret_data
udp_client = espp.UdpSocket(espp.UdpSocket.Config(espp.Logger.Verbosity.debug))
port = 5555
buffer_size = 1024
receive_config = espp.UdpSocket.ReceiveConfig(
port,
buffer_size,
False,
'',
on_receive_data
)
udp_client.start_receiving(espp.Task.BaseConfig("udp_task"), receive_config)
time.sleep(10)
sys.exit(0)