-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalive_server.py
More file actions
38 lines (30 loc) · 1.05 KB
/
alive_server.py
File metadata and controls
38 lines (30 loc) · 1.05 KB
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
from threading import Thread
import socket
class AliveServer(Thread):
"""
Classe de servidor socket que faz o papel de ficar ativo avisando aos outros que a companhia à qual pertence
está ativa.
Atributos:
socket -> socket no qual fica ouvindo as outras companhias
"""
def __init__(self, host):
"""
Instancia um objeto AliveServer e inicializa seus atributos
"""
Thread.__init__(self)
print("Começou o alive server")
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socket.bind(host)
self.socket.listen(5)
def run(self):
"""
Método que é executado quando a Thread é inicializada
Esse método fica em loop infinito com o socket ouvindo todas as requisições
"""
while True:
try:
conn, client = self.socket.accept()
conn.recv(1024).decode()
except:
pass
conn.close()