I have a websocket that should send messages very x seconds. I am connecting to the socket from two clients. THe socket should send the message to both when one of them sends a start message but only the one which doesnt started is getting the message every x seconds. The one which send is getting all messages after all the time passed
This is the loop. The normal send is getting send instant to one that initialized the send (i used this for now as a half fix). My problem is that the send to the group is not send every x second as it should. Only the other connected client are getting it every seconds. The starting person is getting them all at once after the time passed
async def init_starting(self):
if not self.lobby.status == "waiting":
print("Already Started")
return False
else:
print("Starting Countdown")
#self.lobby.status = 'starting'
#await self.save_lobby()
await self.send_status_message_with_status(status='starting', data={'has_started': self.lobby.has_started,
'host': self.host.username,
'players': self.players,
'lobby_code': self.lobby_code,
'countdown': 3})
countdown = 3
while countdown >= 0:
countdown_data = {
'countdown': countdown
}
await self.send(json.dumps({"type": "msg", "message": countdown}))
await self.send_status_message_with_status(status='starting', data=countdown_data)
print(countdown)
countdown -= 1
await asyncio.sleep(1)
await self.send_status_message_with_status(status='started', data={
'message': "Test"
})
return True
async def send_status_message_with_status(self, status, data):
send_data = {
'type': 'status',
'status': str(status),
}
send_data = send_data | data
await self.channel_layer.group_send(
self.lobby_group_code,
send_data
)
THe upper send is working, the lower came in all at once. (on the starting clientside)
THis is the other client side that is not starting. Here are all messages coming in after each seconds passed, so its owrking as it should.
How can i get the group send to be instant on both sides or is there another way to fix this?