# async-socket **Repository Path**: J0hNs0N/async-socket ## Basic Information - **Project Name**: async-socket - **Description**: 封装的非阻塞携程Socket, 实现了TCP服务器(TCPServer)&TCP客户端(TCPClient) - **Primary Language**: Python - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2020-11-08 - **Last Updated**: 2023-10-09 ## Categories & Tags **Categories**: Uncategorized **Tags**: Python, Socket ## README **启动服务器直接使用Python运行 server.py 就可以了** ```shell script python server.py ``` 下面是实际使用的代码 ```python from handler import BaseHandler class SimpeHandler(BaseHandler): def handle(self, data_type, data): print(data) if __name__ == '__main__': server = TCPServer(server_address=("127.0.0.1", 8080), handler_cls=SimpeHandler) server.run_server() while server.is_run: data = input() if data == "exit": server.close() break server.send("text", data) ``` **启动服务器直接使用Python运行 server.py 就可以了** ```shell script python client.py ``` 下面是实际使用的代码 ```python from handler import BaseHandler class SimpeHandler(BaseHandler): def handle(self, data_type, data): print(data) if __name__ == '__main__': client = TCPClient(server_address=("127.0.0.1", 8080), handler_cls=SimpeHandler) client.connect() while client.is_connected: data = input() if data == "exit": client.close() break client.send("text", data) ```