| | |
| | | from socketserver import BaseRequestHandler, UDPServer |
| | | import time |
| | | import os |
| | | import os, sys |
| | | |
| | | |
| | | cudir,_ = os.path.split(__file__) |
| | |
| | | |
| | | packed_count = 0 |
| | | |
| | | class PointCloudUDPServer(BaseRequestHandler): |
| | | class PointCloudUDPRequestHandler(BaseRequestHandler): |
| | | |
| | | def handle(self): |
| | | |
| | | global packed_count |
| | | |
| | | print('Got connection from {}, {}'.format(self.client_address, packed_count)) |
| | | print(time.asctime(),' Got connection from {}, {}'.format(self.client_address, packed_count)) |
| | | # Get message and client socket |
| | | msg, sock = self.request |
| | | f = open('{}/packet{:000006}.udp'.format(file_folder,packed_count), 'wb') |
| | | f = open('{}/packet{}.udp'.format(file_folder,packed_count), 'wb') |
| | | f.write(msg) |
| | | f.close() |
| | | packed_count += 1 |
| | | if packed_count >= 100: |
| | | if packed_count >= 1000000: |
| | | UDPServer.server_close(server) |
| | | |
| | | |
| | | if __name__ == '__main__': |
| | | |
| | | def help(): |
| | | print("Usage: udp_test_get.py [host]. host can be 'test' or 'microwave' ") |
| | | exit(1) |
| | | |
| | | if len(sys.argv) == 2: |
| | | if sys.argv[1] == 'test': |
| | | host = '' |
| | | elif sys.argv[1] == 'microwave': |
| | | host = '192.168.2.65' |
| | | else: |
| | | help() |
| | | else: |
| | | help() |
| | | |
| | | global server |
| | | host = '' |
| | | # host = '192.168.2.65' |
| | | # host = '' |
| | | # host = '192.168.2.65' # use this host to get the udp data from microwave device |
| | | port = 9911 |
| | | server =UDPServer((host, port), PointCloudUDPServer) |
| | | server =UDPServer((host, port), PointCloudUDPRequestHandler) |
| | | print(time.asctime(),'Server started on port', port) |
| | | print('....') |
| | | print('ctrl-c to quit server.') |