1 Star 0 Fork 0

JOHNSON / async-socket

Create your Gitee Account
Explore and code with more than 8 million developers,Free private repositories !:)
Sign up
Clone or Download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

启动服务器直接使用Python运行 server.py 就可以了

python server.py

下面是实际使用的代码

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 就可以了

python client.py

下面是实际使用的代码

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)

Repository Comments ( 0 )

Sign in to post a comment

About

封装的非阻塞携程Socket, 实现了TCP服务器(TCPServer)&TCP客户端(TCPClient) expand collapse
Python
MIT
Cancel

Contributors

All

Activities

Load More
can not load any more
Python
1
https://gitee.com/J0hNs0N/async-socket.git
git@gitee.com:J0hNs0N/async-socket.git
J0hNs0N
async-socket
async-socket
master

Search

101014 b92fc32e 1850385 101014 af024cb7 1850385