Search code examples
python-2.7httptornadobroadcast

How can I send HTTP broadcast message with tornado?


I have a tornado HTTP server.

How can I implement broad-cast message with the tornado server?

Is there any function for that or I just have to send normal HTTP message all clients looping.

I think if I send normal HTTP message, the server should wait for the response.

It seems not the concept of broad-cast.

Otherwise, I need another third-part option for broad-cast?

Please give me any suggestion to implement broad-cast message.


Solution

  • Short answer: you might be interested in WebSockets. Tornado seems to have support for this.

    Longer answer: I assume you're referring to broadcast from the server to all the clients. Unfortunately that's not doable conceptually in HTTP/1.1 because of the way it's thought out. The client asks something of the server, and the server responds, independently of all the others.

    Furthermore, while there is no request going on between a client and a server, that relationship can be said to not exist at all. So if you were to broadcast, you'd be missing out on clients not currently communicating with the server.

    Granted, things are not as simple. Many clients keep a long-lived TCP connection when talking to the server, and pipeline HTTP requests for it on that. Also, a single request is not atomic, and the response is sent in packets. People implemented server-push/long-polling before WebSockets or HTTP/2 with this approach, but there are better ways to go about this now.