Python, Bottle and websockets
Here is a simple websockets demo, using Python and Bottle, based on the example on the Bottle website
- Requirements:
- pip install bottle
- pip install python-dev
- pip install gevent-websocket
- Create websockets.py, from the source code at http://bottlepy.org/docs/dev/async.html#finally-websockets
- python websockets.py
- This starts the (websockets) server. Note that it doesn’t show any output
- Create websockets.html, again from http://bottlepy.org/docs/dev/async.html#finally-websockets
- Make sure to change the websocket address (from “ws://example.com:8080/websocket”). On your local machine this should be “ws://localhost:8080/websocket”
- Load websockets.html in your browser (e.g. as a local file, at file:/// etc)
- This should come up with an alert saying: Your message was ‘Hello, world’