-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdaemon.py
More file actions
34 lines (26 loc) · 1016 Bytes
/
Copy pathdaemon.py
File metadata and controls
34 lines (26 loc) · 1016 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
# -*- coding: utf-8 -*-
import socket
from minion import ChatMinion
from historial import Historial
class ChatDaemon(object):
backlog = 5
hist = None
usuarios = None
def __init__(self, direccion="", puerto=1234):
self.server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.server_socket.bind((direccion, puerto))
self.hist = Historial()
self.usuarios = set()
def inicializar(self):
self.server_socket.listen(self.backlog)
print "[salapy] Iniciando Servidor"
print "[salapy] Esperando conexiones"
while True:
try:
cliente, detalle = self.server_socket.accept()
ChatMinion(cliente, detalle, self.hist, self.usuarios).start()
except KeyboardInterrupt:
self.server_socket.close()
print("Terminó a pedido del usuario ")
exit(0)