Support slow(er) links on receiver

* Use StreamRequestHandler (read a full line)
* Listen on all the interfaces
master
Raphaël Vinot 2015-04-19 22:42:06 +02:00
parent dd39dcb295
commit 530dd2809f
1 changed files with 3 additions and 3 deletions

View File

@ -4,7 +4,7 @@ import socketserver
import redis import redis
class MyTCPHandler(socketserver.BaseRequestHandler): class MyTCPHandler(socketserver.StreamRequestHandler):
""" """
The RequestHandler class for our server. The RequestHandler class for our server.
@ -58,7 +58,7 @@ class MyTCPHandler(socketserver.BaseRequestHandler):
return None return None
print('Start receiving from {}...'.format(self.client_address[0])) print('Start receiving from {}...'.format(self.client_address[0]))
while True: while True:
data = self.request.recv(self.imgsize) data = self.rfile.readline().strip()
if len(data) == 0: if len(data) == 0:
break break
self.r.lpush('new', data) self.r.lpush('new', data)
@ -66,7 +66,7 @@ class MyTCPHandler(socketserver.BaseRequestHandler):
if __name__ == "__main__": if __name__ == "__main__":
HOST, PORT = "localhost", 9999 HOST, PORT = "0.0.0.0", 9999
# Create the server, binding to localhost on port 9999 # Create the server, binding to localhost on port 9999
server = socketserver.TCPServer((HOST, PORT), MyTCPHandler) server = socketserver.TCPServer((HOST, PORT), MyTCPHandler)