As I dive into creating a socket-based application using Django-Channels, I've encountered an issue with connecting to the WebSocket. To demonstrate this problem, I set up a test project.
The error message displayed in the JS Console:
WebSocket connection to 'ws://127.0.0.1:8000/' failed:
The error seems to occur on line 25 of the HTML file, where an instance of WebSocket() is being created.
Here's a snippet of the relevant code:
# consumers.py
import ...
class ChatConsumer(AsyncJsonWebsocketConsumer):
async def connect(self):
self.groupname = 'dashboard'
await self.channel_layer.group_add(
self.groupname,
self.channel_name,
)
await self.accept()
...
... (rest of the code remains unchanged)
Following some investigation, it appears that there may be issues with the channel layers not functioning correctly. I'm unsure if this is the root cause and would appreciate any guidance on resolving it.
P.S. I am currently using Windows and have not implemented Redis. However, I'm uncertain if switching to Redis will eliminate the same issue.