Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is django-channels suitable for real time game?

I want to make a real time game, I wanted to use NodeJS-SocketIO or aiohttp, Until I met django-channels, then i read its documentation.

This is a good module

Questions:

  1. Is django-channels suitable for real time game?
  2. Does django-channels have an advantage over aiohttp/nodejs-socketio?
  3. Is it suitable for all client (android, IOS, desktop)?
like image 233
hadi Avatar asked Aug 05 '17 10:08

hadi


1 Answers

To begin with, channels is nothing but an asynchronous task queue. It's very similar to celery, the major difference being in performance & reliability. Channels is faster than celery but celery is more reliable. To add more context to it, channels executes a task only once (irrespective of whether it fails or succeeds). On the other hand, celery executes the tasks until the tasks fail a certain number of time or it succeeds.

Now, coming to your questions & taking this example.

Suppose you were to build clash of clans using channels & web-sockets.

1) Yes, channels is suitable for real time game as long as you write custom logic for the situations where the task in the async queue fails.

The web-sockets will send & receive messages via channels. So, in case where one of the players' request to deploy a troop on the battlefield is not successfully sent to the server, you need to write custom logic to handle this situation (like trying a request at least 3 times before dumping it out of the task queue).

2) Not really. They are pretty much the same. Ultimately you'll have to use web-sockets & a queue where you can fire/receive messages simultaneously.

3) Yes, you'll have to implement a web-socket in your application (android, iOS, desktop) which'll send/receive messages from the backend via channels.

like image 57
Pranjal Avatar answered Oct 17 '22 12:10

Pranjal