2019-01-05 23:31:56 +00:00
|
|
|
import socketserver
|
2019-03-14 21:38:12 +00:00
|
|
|
import sys
|
2019-01-05 23:31:56 +00:00
|
|
|
|
|
|
|
ADDR = "192.168.1.15"
|
|
|
|
PORT = 20000
|
|
|
|
|
2019-02-23 23:28:33 +00:00
|
|
|
|
2019-03-14 21:38:12 +00:00
|
|
|
def main(argv):
|
|
|
|
serve_file = argv[1]
|
2019-01-05 23:31:56 +00:00
|
|
|
|
2019-03-14 21:38:12 +00:00
|
|
|
def handler(serve_file):
|
|
|
|
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(
|
2019-03-14 21:38:12 +00:00
|
|
|
(ADDR, PORT), handler(serve_file),
|
|
|
|
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__":
|
2019-03-14 21:38:12 +00:00
|
|
|
main(sys.argv)
|