add socket timeout + exit if connection is lost

Fix #2
This commit is contained in:
jkhsjdhjs 2024-01-31 01:01:35 +00:00
parent f92d59dd91
commit 34a3f06d91

View File

@ -72,7 +72,7 @@ def connect(host, port):
global irc
print("Connecting to "+host+":"+str(port))
context = ssl.create_default_context()
with socket.create_connection((host, port)) as sock:
with socket.create_connection((host, port), timeout=180) as sock:
irc = context.wrap_socket(sock, server_hostname=host)
@ -141,6 +141,9 @@ def me(chan, msg):
def getData():
raw = irc.recv(4096)
if not raw:
print("Connection lost!")
sys.exit(0)
try:
data = raw.decode("UTF-8")
except: