mirror of
https://github.com/Xevion/tcp-chat.git
synced 2025-12-06 03:16:44 -06:00
Move shared constants, exceptions & helpers.py into /shared/
This commit is contained in:
@@ -5,7 +5,7 @@ import random
|
||||
from typing import List, Optional, Callable
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import constants
|
||||
from shared import constants
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from server.handler import Client
|
||||
|
||||
@@ -5,7 +5,7 @@ import sqlite3
|
||||
import threading
|
||||
from typing import List, Optional, Union
|
||||
|
||||
import constants
|
||||
from shared import constants
|
||||
|
||||
logger = logging.getLogger('database')
|
||||
logger.setLevel(logging.DEBUG)
|
||||
|
||||
@@ -7,10 +7,10 @@ import uuid
|
||||
from json import JSONDecodeError
|
||||
from typing import Any, List, Optional
|
||||
|
||||
import constants
|
||||
import helpers
|
||||
from shared import constants
|
||||
from shared import helpers
|
||||
# noinspection PyUnresolvedReferences
|
||||
from exceptions import DataReceptionException
|
||||
from shared.exceptions import DataReceptionException
|
||||
from server import db
|
||||
from server.commands import CommandHandler
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import logging
|
||||
import socket
|
||||
import sys
|
||||
import threading
|
||||
|
||||
import constants
|
||||
from shared import constants
|
||||
from server import handler
|
||||
|
||||
host = constants.DEFAULT_IP
|
||||
@@ -10,7 +11,7 @@ port = constants.DEFAULT_PORT
|
||||
|
||||
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
server.bind((host, port))
|
||||
server.listen()
|
||||
server.listen(1)
|
||||
|
||||
logger = logging.getLogger('server')
|
||||
logger.setLevel(logging.DEBUG)
|
||||
@@ -21,8 +22,11 @@ clients = []
|
||||
# Receiving / Listening Function
|
||||
def receive():
|
||||
while True:
|
||||
conn = None
|
||||
|
||||
try:
|
||||
# Accept Connection
|
||||
logger.debug('Waiting for connections...')
|
||||
conn, address = server.accept()
|
||||
logger.info(f"New connection from {address}")
|
||||
|
||||
@@ -39,8 +43,12 @@ def receive():
|
||||
thread.start()
|
||||
except KeyboardInterrupt:
|
||||
logger.info('Server closed by user.')
|
||||
if conn:
|
||||
conn.close()
|
||||
break
|
||||
except Exception as e:
|
||||
logger.critical(e, exc_info=e)
|
||||
break
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user