限制客户端发送给服务器的最大消息数

时间:2017-09-05 08:50:52

标签: python websocket python-asyncio

我需要限制客户端在特定时间内可以发送的连接。我的服务器接受来自客户端的单个连接的多个请求。

async def handle_client ( websocket, path):
    while 1:
        data =await websocket.recv( )

        #some long process here  1-2 seconds

        await websocket.send(result_from_long_process)

    return
        # One possibiliy is to find requests received from a
        # client per second  and if it is > threshold disconnect the client.
        # But how to find when the server got the specific request from client

loop = asyncio.get_event_loop( )
HOST = ''
PORT = 9116
server = websockets.serve(handle_client, HOST, PORT)
loop.run_until_complete(server)
loop.run_forever( )

0 个答案:

没有答案