-
Notifications
You must be signed in to change notification settings - Fork 29
/
serverAudio.py
44 lines (36 loc) · 1.08 KB
/
serverAudio.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from socket import socket, AF_INET, SOCK_STREAM
from threading import Thread
HOST = input("Enter Host IP\n")
PORT = 4000
BufferSize = 4096
addresses = {}
def Connections():
while True:
try:
client, addr = server.accept()
print("{} is connected!!".format(addr))
addresses[client] = addr
Thread(target=ClientConnectionSound, args=(client, )).start()
except:
continue
def ClientConnectionSound(client):
while True:
try:
data = client.recv(BufferSize)
broadcastSound(client, data)
except:
continue
def broadcastSound(clientSocket, data_to_be_sent):
for client in addresses:
if client != clientSocket:
client.sendall(data_to_be_sent)
server = socket(family=AF_INET, type=SOCK_STREAM)
try:
server.bind((HOST, PORT))
except OSError:
print("Server Busy")
server.listen(2)
print("Waiting for connection..")
AcceptThread = Thread(target=Connections)
AcceptThread.start()
AcceptThread.join()