-
Notifications
You must be signed in to change notification settings - Fork 302
Expand file tree
/
Copy pathudp_send_marker.py
More file actions
42 lines (36 loc) · 1.17 KB
/
udp_send_marker.py
File metadata and controls
42 lines (36 loc) · 1.17 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
import socket
import random
import struct
import time
import argparse
if __name__ == "__main__":
test_duration = 10
# Collect command line arguments
parser = argparse.ArgumentParser()
parser.add_argument("--ip", default="127.0.0.1",
help="The IP of the UDP server")
parser.add_argument("--port", type=int, default=12340,
help="The port the UDP server is sending to")
args = parser.parse_args()
# Establish UDP socket
UDP_IP = args.ip
UDP_PORT = args.port
sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
# Display socket attributes
print('---------------------')
print("-- UDP MARKER SEND -- ")
print('---------------------')
print("IP:", args.ip)
print("PORT:", args.port)
print('--------------------=')
# Send test data
start = time.time()
while time.time() <= start + test_duration:
# generate random float
marker = random.uniform(0, 4)
# package as byte array
msg = struct.pack('!f', marker)
# send through socket
sock.sendto(msg, (UDP_IP, UDP_PORT))
time.sleep(.25)