ii-vision/server/server.py

40 lines
1.0 KiB
Python
Raw Normal View History

import argparse
2019-01-05 23:31:56 +00:00
import socketserver
parser = argparse.ArgumentParser(
description='Serve a video to ][Vision clients.')
parser.add_argument(
'input', help='Path to input video file.')
parser.add_argument(
'--port', type=int,
# 6502 is used by ADTPro so use another nice number
default=1977,
help='Port number to serve on.')
2019-02-23 23:28:33 +00:00
def main(args):
serve_file = args.input
2019-01-05 23:31:56 +00:00
2019-03-15 21:08:31 +00:00
def handler():
2019-03-14 21:38:12 +00:00
class ChunkHandler(socketserver.BaseRequestHandler):
def handle(self):
with open(serve_file, "rb") as f:
data = f.read()
print("Sending %d bytes" % len(data))
self.request.sendall(data)
2019-01-05 23:31:56 +00:00
2019-03-14 21:38:12 +00:00
return ChunkHandler
2019-01-05 23:31:56 +00:00
with socketserver.TCPServer(
("0.0.0.0", args.port), handler(),
2019-03-14 21:38:12 +00:00
bind_and_activate=False) as server:
2019-01-05 23:31:56 +00:00
server.allow_reuse_address = True
server.server_bind()
server.server_activate()
server.serve_forever()
if __name__ == "__main__":
main(parser.parse_args())