Skip to content

Instantly share code, notes, and snippets.

@DustinAlandzes
Last active April 24, 2018 19:56
Show Gist options
  • Save DustinAlandzes/122413c67197e8a3c251f1528eb8f69b to your computer and use it in GitHub Desktop.
Save DustinAlandzes/122413c67197e8a3c251f1528eb8f69b to your computer and use it in GitHub Desktop.
from channels.generic import websockets
class ExampleConsumer(websockets.JsonWebsocketConsumer):
def receive(self, content):
print(content) # {"test": "data"}
from channels.routing import route_class
from consumers import ExampleConsumer
channel_routing = [
route_class(ExampleConsumer)
]
var ws = new WebSocket("ws://localhost:8000/")
var msg = JSON.stringify({"test": "data"})
ws.send(msg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment