Support slow(er) links on receiver
* Use StreamRequestHandler (read a full line) * Listen on all the interfacesmaster
parent
dd39dcb295
commit
530dd2809f
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue