-
Notifications
You must be signed in to change notification settings - Fork 8
/
udp-server.py
33 lines (25 loc) · 849 Bytes
/
udp-server.py
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
import select, socket
import argparse
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('--port', type=int, help='tcp port', default=6789)
args = parser.parse_args()
print("args.port={}".format(args.port))
server_ip = "0.0.0.0" # Both Limited Broadcast/Directed Broadcast/Unicast
#server_ip = "255.255.255.255" # Only Limited broadcast
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind( (server_ip, args.port) )
sock.setblocking(0)
print("+==========================+")
print("| ESP32 UDP Logging Server |")
print("+==========================+")
print("")
while True:
result = select.select([sock],[],[])
data = result[0][0].recv(1024)
if (type(data) is bytes):
data = data.decode('utf-8')
print(data, end='')