wu_xinjun
2022-05-13 33224139e89b8c971b8b2442a2aae9dbd92063f5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import time
import socket
import os, sys
 
cudir,_ = os.path.split(__file__)
file_folder = os.path.join(cudir,"demoData")
 
packed_count = 0
if __name__ == '__main__':
 
    files = ["packet{}.udp".format(i) for i in range(0, 100)]
    for file in files:
        with open(os.path.join(file_folder,file), "rb") as f:
            message = f.read()
            client_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            client_socket.settimeout(1.0)
            addr = ("127.0.0.1", 9911)
            client_socket.sendto(message, addr)
            print (time.asctime(), f' Sending {file} to {addr} ...')
            time.sleep(0.1)
    print('Done!')