feat: complete client-server architecture refactoring
Server: - Split into views, routes, helpers, models modules - Merged /ws/talk and /ws/update into single /ws/chat endpoint - Replaced polling with push-based broadcast model - Added username uniqueness validation on connect - Fixed run_server arguments bug (workers parameter) - Removed deprecated loop argument from Sanic listeners - Replaced datetime.utcnow() with timezone-aware datetime.now(timezone.utc) Client: - Rewrote client as single-file module - Migrated from websocket-client to websockets (asyncio) - Fixed websocket-client conflict with asyncio event loop on Windows - Added progress indicators for key generation, exchange, connection - Added animated 3D spinning cube in UI - Updated RSA key from 512 to 2048 bits CLI: - Removed unnecessary asyncio.run() wrapper - Simplified entry point
This commit is contained in:
+23
-22
@@ -1,38 +1,39 @@
|
||||
import asyncio
|
||||
import argparse
|
||||
from cmd_chat.server.server import run_server
|
||||
from cmd_chat.client.client import Client
|
||||
|
||||
|
||||
def run_http_server(ip: str, port: int, password: str | None) -> None:
|
||||
run_server(ip, int(port), False, password)
|
||||
run_server(host=ip, port=int(port), admin_password=password)
|
||||
|
||||
async def run_client(username: str, server: str, port: int, password: str | None) -> None:
|
||||
Client(server=server, port=port, username=username, password=password).run()
|
||||
|
||||
async def run() -> None:
|
||||
parser = argparse.ArgumentParser(description='Command-line chat application')
|
||||
subparsers = parser.add_subparsers(dest='command', required=True)
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Command-line chat application")
|
||||
subparsers = parser.add_subparsers(dest="command", required=True)
|
||||
|
||||
serve_p = subparsers.add_parser('serve', help='Run server')
|
||||
serve_p.add_argument('ip_address')
|
||||
serve_p.add_argument('port')
|
||||
serve_p.add_argument('--password', '-p', required=True, help='Admin password required for clients')
|
||||
serve_p = subparsers.add_parser("serve", help="Run server")
|
||||
serve_p.add_argument("ip_address")
|
||||
serve_p.add_argument("port")
|
||||
serve_p.add_argument("--password", "-p", required=True)
|
||||
|
||||
connect_p = subparsers.add_parser('connect', help='Connect to server')
|
||||
connect_p.add_argument('ip_address')
|
||||
connect_p.add_argument('port')
|
||||
connect_p.add_argument('username')
|
||||
connect_p.add_argument('password', help='Password to auth on server')
|
||||
connect_p = subparsers.add_parser("connect", help="Connect to server")
|
||||
connect_p.add_argument("ip_address")
|
||||
connect_p.add_argument("port")
|
||||
connect_p.add_argument("username")
|
||||
connect_p.add_argument("password")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.command == 'serve':
|
||||
if args.command == "serve":
|
||||
run_http_server(args.ip_address, args.port, args.password)
|
||||
elif args.command == 'connect':
|
||||
await run_client(args.username, args.ip_address, int(args.port), args.password)
|
||||
elif args.command == "connect":
|
||||
Client(
|
||||
server=args.ip_address,
|
||||
port=int(args.port),
|
||||
username=args.username,
|
||||
password=args.password,
|
||||
).run()
|
||||
|
||||
def main():
|
||||
asyncio.run(run())
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user