I have a server that receives audio stream data from a client and then sends it to all other connected clients (via sockets). Since the data stream makes the code stuck on a loop , I decided that I should create processes for each stream (client essentially). I noticed that even with one connected client , the process makes the audio lag. Why is that ? That also happens if I try to use threads.
Code:
p_r = Process(target=playback_f,
args=(pass_record, soc, client, port_a, data, c)).start()
Where soc
is the socket connection of the client in question, data
is the initial data and c
is the result of:
c, addr1 = s.accept()
The process calls:
def playback_f(pass_record, soc, client, port_a, data, c):
try:
stop_recording = False
try :
soc.sendto('playback'.encode('utf-8'),(client,port_a))
except Exception as e:
print (e)
while stop_recording == False:
if data != b'stop_rec':
try:
data = c.recv(1024)
soc.sendto(data,(client,port_a))
except Exception as e:
print (e)
else:
stop_recording = True
print('ended')
except Exception as e:
print(e)