mirror of
https://github.com/Xevion/tcp-chat.git
synced 2025-12-06 13:16:42 -06:00
create improved server/client commandline launching method
This commit is contained in:
21
launch.py
21
launch.py
@@ -1,8 +1,17 @@
|
|||||||
from PyQt5.QtWidgets import QApplication
|
import sys
|
||||||
from client.gui import MainWindow
|
|
||||||
|
|
||||||
app = QApplication([])
|
if __name__ == "__main__":
|
||||||
app.setApplicationName("TCPChat Client")
|
if len(sys.argv) != 2:
|
||||||
m = MainWindow()
|
print('Please provide one argument besides the file describing whether to launch the client or server.')
|
||||||
|
print('Client/C/1 to launch the client. Server/S/2 to launch the server.')
|
||||||
|
else:
|
||||||
|
if str(sys.argv[1]).lower() in ['client', 'c', '1']:
|
||||||
|
from PyQt5.QtWidgets import QApplication
|
||||||
|
from client.gui import MainWindow
|
||||||
|
|
||||||
app.exec_()
|
app = QApplication([])
|
||||||
|
app.setApplicationName("TCPChat Client")
|
||||||
|
m = MainWindow()
|
||||||
|
app.exec_()
|
||||||
|
elif str(sys.argv[1]).lower() == ['server', 's', '2']:
|
||||||
|
from server import main
|
||||||
|
|||||||
0
server/__init__.py
Normal file
0
server/__init__.py
Normal file
@@ -17,6 +17,7 @@ logger = logging.getLogger('server')
|
|||||||
|
|
||||||
clients = []
|
clients = []
|
||||||
|
|
||||||
|
|
||||||
# Receiving / Listening Function
|
# Receiving / Listening Function
|
||||||
def receive():
|
def receive():
|
||||||
while True:
|
while True:
|
||||||
@@ -25,8 +26,12 @@ def receive():
|
|||||||
logger.info(f"New connection from {address}")
|
logger.info(f"New connection from {address}")
|
||||||
|
|
||||||
client = handler.Client(conn, address, clients)
|
client = handler.Client(conn, address, clients)
|
||||||
|
clients.append(client)
|
||||||
client.request_nickname()
|
client.request_nickname()
|
||||||
|
|
||||||
# Start Handling Thread For Client
|
# Start Handling Thread For Client
|
||||||
thread = threading.Thread(target=client.handle, name=client.id[:8])
|
thread = threading.Thread(target=client.handle, name=client.id[:8])
|
||||||
thread.start()
|
thread.start()
|
||||||
|
|
||||||
|
|
||||||
|
receive()
|
||||||
|
|||||||
Reference in New Issue
Block a user