-
Notifications
You must be signed in to change notification settings - Fork 0
/
SilvairServer.py
34 lines (30 loc) · 957 Bytes
/
SilvairServer.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
from Exceptions import ConnectException
from threading import Thread
from ClientConnection import ClientCon
import socket
class Server:
"""The class for an IRC Server"""
def __init__(self, bind, port):
if bind is None:
bind = ""
self.port = port
self.bind = bind
self.isListening = False
self._sock = None
def _listen(self):
self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self._sock.bind((self.bind, self.port))
self._sock.listen(1)
try:
while True:
con, addr = self._sock.accept()
ClientCon(con, addr)
except Exception, ex:
raise ex
finally:
self._sock.close()
def listen(self):
if self.isListening:
raise ConnectException("already listening")
self.isListening = True;
Thread(target = self._listen).start()