Sending messages to the group does not work after a few minutes online

46 views
Skip to first unread message

Luís Antonio De Marchi

unread,
Aug 5, 2017, 7:50:32 PM8/5/17
to Django developers (Contributions to Django itself)
I'm using:
Django==1.11.3
channels
==1.1.6


When the user connects to the websocket, I do the following:

@channel_session
def connect(self, message, **kwargs):
    group = Group('user-%s' % user.uuid)
    # Do not use more than one device.
    group.send({"close": True}, immediately=True)
    group.add(self.message.reply_channel)

I've created this method to send information to some specific user:


from channels.generic.websockets import WebsocketMultiplexer
def custom_reply(uuid: UUID, stream, action, data={}, response_status=200):
   
if type(action) is ActionType:
        action
= action.value

    payload
= {
       
'errors': [],
        'data': data,
        'action': action,
        'response_status': response_status
   
}

   
WebsocketMultiplexer.group_send(name='user-%s' % uuid,
                                    stream=stream,
                                    payload=payload)



 For several minutes this method sends the message to the client, after a while it seems that the users within the group are being reset and then the client is losing message

Andrew Godwin

unread,
Aug 5, 2017, 7:58:25 PM8/5/17
to Django developers (Contributions to Django itself)
It seems you send "close": True to the group when a connection comes in, which means that only one websocket at a time is going to be open in it (all others in the group will be disconnected when a new one connects)

Andrew

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscribe@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/4a819a9c-b791-4c89-a996-09ab2e07a2ed%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages