Coder Social home page Coder Social logo

django-websockets-no-dep's Introduction

django-websockets-no-dep

Django 3.0 with ASGI + web-sockets implementation with no dep

Trying it out

Prerequisite

You need to have installed in your system docker + docker-compose

Running the project

First build the images, this can take some time based on your Mbps

docker-compose build

Then start the containers

docker-compose up

Now you will be able to access to your localhost on port 8000

Testing it

Firts let's create a websocket connection, open your browser and in the console run

ws = new WebSocket('ws://localhost:8000/')

Then set a on message function

ws.onmessage = event => console.log(event.data)

Now from a http client (postman, curl, browser, etc) hit the endpoint GET http://localhost:8000/trigger_event/

You will get a json response {"status": "ok"}

Now take a look at the console, you should see a console log Event triggered

django-websockets-no-dep's People

Contributors

lautaronavarro avatar

Stargazers

Tushar Sarang avatar Mike avatar Oliver Mas avatar  avatar Lautaro Navarro avatar Mario HD avatar Stephen M. Kinyanjui avatar  avatar

Watchers

Oliver Mas avatar James Cloos avatar

Forkers

usamawizard

django-websockets-no-dep's Issues

WebSockets and PUB/SUB

That's interesting ... thank you for sharing this.
Are you trying to let a WebSocket client subscribe a Pub/Sub channel?
I experimented a different approach for this: having a single background process subscribing the channel, then from here broadcast any received message to the connected WebSocket clients.
I discussed it in a talk available here (the relevant part starts at 18:00):

https://www.youtube.com/embed/V8VAQS7xais?autoplay=1

At that time, Django 3 was not available, so I used Django Channels; but I'm reconsidering this.

Should you be interested, I'ld love to discuss this topic, and compare the two approaches; I never did any benchmark yet, and would be very interested in considering the different implications in terms of performance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.