aiortc / aioquic

QUIC and HTTP/3 implementation in Python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

serve more than one client simultaneously.

secondaviv opened this issue · comments

This possible to serve more than one client simultaneously?
For example: client A send a request and the server do calculate that take long time.
Client B sends request get response and then client A get response after the server finish the calculation.

The following example doesn't work for me:
in examples/http3_server.py/HttpRequestHandler/run_asgi I change to following code:

async def run_asgi(self, app: AsgiApplication) -> None:
    path = self.scope['path']      

    if path == '/b':            
        self.connection.send_headers(
            stream_id=self.stream_id,
            headers=[
                (b":status", b"ok"),
                (b"server", SERVER_NAME.encode()),
                (b"date", formatdate(time.time(), usegmt=True).encode()),
            ],
        )
        self.connection.send_data(
            stream_id=self.stream_id,
            data=b'bb',
            end_stream=True,#end
        )
    else: #path == '/a':   
        await asyncio.sleep(10)############################sleep                  
        self.connection.send_headers(
            stream_id=self.stream_id,
            headers=[
                (b":status", b"ok"),
                (b"server", SERVER_NAME.encode()),
                (b"date", formatdate(time.time(), usegmt=True).encode()),
            ],
        )
        self.connection.send_data(
            stream_id=self.stream_id,
            data=b'a',
            end_stream=True,#end
        )

on the server I run

python3.10 examples/http3_server_simultaneously.py --certificate tests/ssl_cert.pem --private-key tests/ssl_key.pem

on the client I run

python3.10 examples/http3_client.py --ca-certs tests/pycacert.pem https://10.0.2.12:4433/a

and from different terminal after less than one second I run:

python3.10 examples/http3_client.py --ca-certs tests/pycacert.pem https://10.0.2.12:4433/b

I expected to get a response in client B first. And then get a response in client A.
In actual fact client A not get a response.

Have way to serve client B before client A response?

Yes the example server provided with aioquic is able to serve multiple clients. No idea about your custom code, I don't understand why you're changing the server code instead of just the ASGI app.