Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference/compatibility between aiohttp and websockets?

What's the difference between aiohttp's websocket support (i.e. WebSocketResponse) and websockets (both offer an async support)? Can they be mixed?

like image 750
Rhangaun Avatar asked May 16 '16 14:05

Rhangaun


People also ask

What is aiohttp used for?

aiohttp is used to build useful libraries built on top of it, and there's a page dedicated to list them: Third-Party libraries. There are also projects that leverage the power of aiohttp to provide end-user tools, like command lines or software with full user interfaces.

Is aiohttp a framework?

The aiohttp (http://aiohttp.readthedocs.io/) framework is a popular asynchronous framework based on the asyncio library, which has been around since the first days of the library. Like Flask, it provides a request object and a router to redirect queries to functions that handle them.

Can you use websockets with Heroku?

It provides a bidirectional channel for delivering data between clients and servers. It gives you the flexibility of a TCP connection with the additional security model and meta data built into the HTTP protocol. For more details on the WebSocket protocol refer to RFC 6455, which is the version supported on Heroku.


1 Answers

They are two different libraries maintained by different people. Both are built on top of asyncio.

websockets aims to be a simple easy to use library to implement websockets clients and servers and is maintained mostly by a single developer. On the other hand, aiohttp is a quite bigger library maintained by bigger team, offering not only websockets but, as the name suggests, HTTP functionality as well. Some of its functionality overlaps that of flask and requests, but in a async fashion.

In terms of size, websockets is about 4k LOC, while aiohttp is about 40k LOC. If you just need a simple and easy to use websockets client, go for websockets. If you are already using aiohttp and need websockets functionality, use what aiohttp has to offer. I don't see a point in mixing them.

like image 75
Gustavo Bezerra Avatar answered Nov 15 '22 08:11

Gustavo Bezerra