Client using http persistent connection

Hello everyone, first of all, thanks to all the community for providing support and making such an amazing job.

I am trying to use Sanic to receive a video feed from FFmpeg, basically instructing FFmpeg to upload video chunks to Sanic server but using a persistent http connection. (Why? because continuously open/close the connection is not feasible for networks with big latencies)

I am not able to understand how to define the route and through wireshark I see a request like this:

110.805096	10.78.84.251	172.25.99.244	HTTP	1405	PUT /0001/init-stream0.m4s HTTP/1.1 PUT /0001/chunk-stream0-00001.m4s HTTP/1.1 

Basically two PUT requests in one and then a continuation.

With Sanic 19 and 20 I receive different errors but first of all I would like to ask how can I setup a route
to receive data from a persistent channel

I tried the following without success:

@app.route("/<istream_id>/init-stream<itrack_id:int>.m4s/<cstream_id>/chunk-stream<ctrack_id:int>-<segment_number>.m4s", methods=["POST", "PUT","DELETE"], stream=False)
async def upload_file(request, istream_id, cstream_id, itrack_id, ctrack_id,  segment_number):

@app.route("/<stream_id>/chunk-stream<track_id:int>-<segment_number>\.<extension>", methods=["POST", "PUT","DELETE"], stream=True)
async def upload_file(request, stream_id, track_id, segment_number, extension):

In the documentation I found the follwoing but still no luck:

@app.post('/stream', stream=True)
async def handler(request):
    async def streaming(response):
        while True:
            body = await request.stream.get()
            if body is None:
                break
            body = body.decode('utf-8').replace('1', 'A')
            await response.write(body)
    return stream(streaming)

Any ideas?
Thanks!

Jay

For who is interested, I solved using an ASGI server, uvicorn in the specific, that supports http pipelines.

Thanks
Jay

:+1: Not a feature of Sanic server right now. Perfect use case for ASGI-mode. Glad you found it.

1 Like