-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
44 lines (36 loc) · 985 Bytes
/
Copy pathserver.py
File metadata and controls
44 lines (36 loc) · 985 Bytes
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 concurrent.futures import thread
from email import message
from pydoc import cli
import threading
import socket
from numpy import broadcast
clients = []
def main():
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
server.bind(('localhost', 7888))
server.listen()
print('Server online ')
except:
return print('Houve prolema na conexao')
while True:
client, addr = server.accept()
clients.append(client)
thread = threading.Thread(target=messageTreatment, args=[client])
thread.start()
def messageTreatment(client):
while True:
try:
msg = client.recv(1024)
broadcast(msg, client)
except:
clients.remove(client)
break
def broadcast(msg, client):
for cli in clients:
if cli != client:
try:
cli.send(msg)
except:
clients.remove(cli)
main()