sockets - Python TCP Relay/Proxy Server locking up -
i have simple python proxy server i've setup. purpose take tcp stream (video) , forward tcp stream several clients (currently testing 1 start). works great until try forward (o.send(data)) data , receive/send couple packets, freeze , minute or 2 later receive/send few more packets , freeze again.
if take incoming data , load variable doesn't slow down @ all. , if both load incoming data data variable send random block of data client instead of received data doesn't freeze. feel maybe there race condition or .recv() shouldn't block don't know deadlock coming from. data flled recv, should able send right? , rinse/repeat indefinitely. can check cpu utilization top -bn1 , python script doesn't appear using cpu @ all.
the deadlock happens between .recv() , .send().
if put in debug print it'll print "data received!" ..... pause ... "data sent!" "data received!"....
import socket # listen gstreamer tcp stream. s = socket.socket(socket.af_inet, socket.sock_stream) s.bind(("192.168.1.1", 911)) s.listen(5) # connect video player o = socket.socket(socket.af_inet, socket.sock_stream) o.connect(("192.168.2.2",910)) clientsocket, address = s.accept() while 1: # receive video data. data = clientsocket.recv(4096) # forward video player o.send(data) print 'o'
thanks!
one of nics faulty. swapped nic , worked fine. not sure why presented in 1 way @ least found solution.