Django Websockets / Several Users on the Website

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Django Websockets / Several Users on the Website

matrix1900
Hi together,

I try to get started with Django Channels.  I have actually two questions:

1. I use web sockets with channels. I want to have for each frontend user which opens the website his own websocket channel without groups. I am not sure how does it works when several Users opens the website ? Has each frontend user his own consumer thread which handles the web socket messages ? How are the concept here?

2. How can I receive websocket messages in a separate task. I found in the FAQ on the Channels Site the hint to use receive_many() but I'm not sure how to use it exactly.

3. How can I start a separate task  in the consumer.py after receive a message ('websocket.receive')
( for example: In Consumer I get a message via websocket from the frontend user, according to the message I start a process with some arguments, after execute the process,  I get the results back and send it to the individual  websocket channel client)

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b4fc5aba-e9a4-4187-84da-24b08348ec5e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Django Websockets / Several Users on the Website

Andrew Godwin-3


On Wed, Oct 11, 2017 at 3:02 AM, 'matrix1900' via Django users <[hidden email]> wrote:
Hi together,

I try to get started with Django Channels.  I have actually two questions:

1. I use web sockets with channels. I want to have for each frontend user which opens the website his own websocket channel without groups. I am not sure how does it works when several Users opens the website ? Has each frontend user his own consumer thread which handles the web socket messages ? How are the concept here?

The server holds on to all the websockets in one big async thread, then calls your Django code synchronously whenever an event happens on the socket.
 

2. How can I receive websocket messages in a separate task. I found in the FAQ on the Channels Site the hint to use receive_many() but I'm not sure how to use it exactly.

You shouldn't do this, use the normal worker pattern, there's lot more than just receive_many to do
 

3. How can I start a separate task  in the consumer.py after receive a message ('websocket.receive')
( for example: In Consumer I get a message via websocket from the frontend user, according to the message I start a process with some arguments, after execute the process,  I get the results back and send it to the individual  websocket channel client)


You have to send it to a custom channel with the reply_channel of the socket, have a worker listen on that channel, and when it is done send information back to the reply_channel.

Andrew
 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFwN1uqiCoduLg8G9T4AHnc4N26chwjcRw5wiCB0dXVdFiTuBw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Django Websockets / Several Users on the Website

matrix1900
Hi Andrew,

thanks for the answer.
Are there some Examples available for using Background Worker and  receive/send websockets in there ?

I am not sure, if it is the better way to use celery or should I use the background worker?
My Project:
I should develop a maintain website for a automation control.  Each user can view different sensor values (Described on several websites) from the automation control.
 
IDEA: Each user have his own background worker which request the sensor values from the automation control and send the information to the user. The sensor values are updated upon change. (Providing Live DATA)


Am Donnerstag, 12. Oktober 2017 20:05:42 UTC+2 schrieb Andrew Godwin:


On Wed, Oct 11, 2017 at 3:02 AM, 'matrix1900' via Django users <<a onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;" href="javascript:" target="_blank" rel="nofollow" gdf-obfuscated-mailto="uNS7HUFMAwAJ">django...@...> wrote:
Hi together,

I try to get started with Django Channels.  I have actually two questions:

1. I use web sockets with channels. I want to have for each frontend user which opens the website his own websocket channel without groups. I am not sure how does it works when several Users opens the website ? Has each frontend user his own consumer thread which handles the web socket messages ? How are the concept here?

The server holds on to all the websockets in one big async thread, then calls your Django code synchronously whenever an event happens on the socket.
 

2. How can I receive websocket messages in a separate task. I found in the FAQ on the Channels Site the hint to use receive_many() but I'm not sure how to use it exactly.

You shouldn't do this, use the normal worker pattern, there's lot more than just receive_many to do
 

3. How can I start a separate task  in the consumer.py after receive a message ('websocket.receive')
( for example: In Consumer I get a message via websocket from the frontend user, according to the message I start a process with some arguments, after execute the process,  I get the results back and send it to the individual  websocket channel client)


You have to send it to a custom channel with the reply_channel of the socket, have a worker listen on that channel, and when it is done send information back to the reply_channel.

Andrew
 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7ebb5b85-064b-421f-a906-a638ba97bb10%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Django Websockets / Several Users on the Website

Roger Gammans-2
One architecture you could consider, is to put all the sensor values into redis or similar. Have a worker to out the values into redis from the automation source.

Then use each websocket recieve event to add the reply channel to the group which gets the appropriate sensor value.

You will probably need a second worker to forward redis messages to the appropriate group.

But you can end up with the the values going down a couple of channels, and each user doesn't need a separate worker. 

Personally I'd do as much of be the filtering on the client side as possible, if there is no security concern with publishing the values to a user send the values to them. The client side code can ignore it if necessary.



On 13 Oct 2017 07:14, "'matrix1900' via Django users" <[hidden email]> wrote:
Hi Andrew,

thanks for the answer.
Are there some Examples available for using Background Worker and  receive/send websockets in there ?

I am not sure, if it is the better way to use celery or should I use the background worker?
My Project:
I should develop a maintain website for a automation control.  Each user can view different sensor values (Described on several websites) from the automation control.
 
IDEA: Each user have his own background worker which request the sensor values from the automation control and send the information to the user. The sensor values are updated upon change. (Providing Live DATA)


Am Donnerstag, 12. Oktober 2017 20:05:42 UTC+2 schrieb Andrew Godwin:


On Wed, Oct 11, 2017 at 3:02 AM, 'matrix1900' via Django users <[hidden email]> wrote:
Hi together,

I try to get started with Django Channels.  I have actually two questions:

1. I use web sockets with channels. I want to have for each frontend user which opens the website his own websocket channel without groups. I am not sure how does it works when several Users opens the website ? Has each frontend user his own consumer thread which handles the web socket messages ? How are the concept here?

The server holds on to all the websockets in one big async thread, then calls your Django code synchronously whenever an event happens on the socket.
 

2. How can I receive websocket messages in a separate task. I found in the FAQ on the Channels Site the hint to use receive_many() but I'm not sure how to use it exactly.

You shouldn't do this, use the normal worker pattern, there's lot more than just receive_many to do
 

3. How can I start a separate task  in the consumer.py after receive a message ('websocket.receive')
( for example: In Consumer I get a message via websocket from the frontend user, according to the message I start a process with some arguments, after execute the process,  I get the results back and send it to the individual  websocket channel client)


You have to send it to a custom channel with the reply_channel of the socket, have a worker listen on that channel, and when it is done send information back to the reply_channel.

Andrew
 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7ebb5b85-064b-421f-a906-a638ba97bb10%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2B_0JkLtGUd49FNoAt6jBZeNp7%2Bj7PPOh2UF%3DogOAWBxg_CjwQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Django Websockets / Several Users on the Website

matrix1900
thanks for the advise. But the requirement is to reduce the data transfer to the client as less as possible. I want to send only the data which the client needs. And only send  the data values that are changed for live data view.


Am Freitag, 13. Oktober 2017 11:17:16 UTC+2 schrieb Roger Gammans:
One architecture you could consider, is to put all the sensor values into redis or similar. Have a worker to out the values into redis from the automation source.

Then use each websocket recieve event to add the reply channel to the group which gets the appropriate sensor value.

You will probably need a second worker to forward redis messages to the appropriate group.

But you can end up with the the values going down a couple of channels, and each user doesn't need a separate worker. 

Personally I'd do as much of be the filtering on the client side as possible, if there is no security concern with publishing the values to a user send the values to them. The client side code can ignore it if necessary.



On 13 Oct 2017 07:14, "'matrix1900' via Django users" <<a onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;" href="javascript:" target="_blank" rel="nofollow" gdf-obfuscated-mailto="BPnQXP99AwAJ">django...@...> wrote:
Hi Andrew,

thanks for the answer.
Are there some Examples available for using Background Worker and  receive/send websockets in there ?

I am not sure, if it is the better way to use celery or should I use the background worker?
My Project:
I should develop a maintain website for a automation control.  Each user can view different sensor values (Described on several websites) from the automation control.
 
IDEA: Each user have his own background worker which request the sensor values from the automation control and send the information to the user. The sensor values are updated upon change. (Providing Live DATA)


Am Donnerstag, 12. Oktober 2017 20:05:42 UTC+2 schrieb Andrew Godwin:


On Wed, Oct 11, 2017 at 3:02 AM, 'matrix1900' via Django users <[hidden email]> wrote:
Hi together,

I try to get started with Django Channels.  I have actually two questions:

1. I use web sockets with channels. I want to have for each frontend user which opens the website his own websocket channel without groups. I am not sure how does it works when several Users opens the website ? Has each frontend user his own consumer thread which handles the web socket messages ? How are the concept here?

The server holds on to all the websockets in one big async thread, then calls your Django code synchronously whenever an event happens on the socket.
 

2. How can I receive websocket messages in a separate task. I found in the FAQ on the Channels Site the hint to use receive_many() but I'm not sure how to use it exactly.

You shouldn't do this, use the normal worker pattern, there's lot more than just receive_many to do
 

3. How can I start a separate task  in the consumer.py after receive a message ('websocket.receive')
( for example: In Consumer I get a message via websocket from the frontend user, according to the message I start a process with some arguments, after execute the process,  I get the results back and send it to the individual  websocket channel client)


You have to send it to a custom channel with the reply_channel of the socket, have a worker listen on that channel, and when it is done send information back to the reply_channel.

Andrew
 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;" href="javascript:" target="_blank" rel="nofollow" gdf-obfuscated-mailto="BPnQXP99AwAJ">django-users...@googlegroups.com.
To post to this group, send email to <a onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;" href="javascript:" target="_blank" rel="nofollow" gdf-obfuscated-mailto="BPnQXP99AwAJ">django...@....
Visit this group at <a onmousedown="this.href=&#39;https://groups.google.com/group/django-users&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/django-users&#39;;return true;" href="https://groups.google.com/group/django-users" target="_blank" rel="nofollow">https://groups.google.com/group/django-users.
To view this discussion on the web visit <a onmousedown="this.href=&#39;https://groups.google.com/d/msgid/django-users/7ebb5b85-064b-421f-a906-a638ba97bb10%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/django-users/7ebb5b85-064b-421f-a906-a638ba97bb10%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" href="https://groups.google.com/d/msgid/django-users/7ebb5b85-064b-421f-a906-a638ba97bb10%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow">https://groups.google.com/d/msgid/django-users/7ebb5b85-064b-421f-a906-a638ba97bb10%40googlegroups.com.

For more options, visit <a onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" href="https://groups.google.com/d/optout" target="_blank" rel="nofollow">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f1644ebe-2573-438f-865e-da054da0bfe6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.