Realtime: Making intefaces for fun and the impatient
This semester we've done a lot of GET & POST & GET & POST. We've waiting for pages to redirect and load.
There are a few tools/techniques that support semi-realtime and realtime interface experiences. The best example is a chat room where after you post a messsage the message is shared with the room and the page doesn't need to refresh. Or you might think of GMail where your email autoloads as it arrives (or loads with a slight delay).
Websockets allow clients (ie browsers) stay connected via a persistent connection to a server. This allows the server to PUSH data to clients in a near realtime experience. The clients may also PUSH data back to the server which might be broadcasted to all other clients.
Websockets are fairly new, Heroku just started to support them only last month.
Open code directory in Terminal console.
Create Virtualenv (only needs to be run once).
Initial PIP requirements install / Or when you need to update Python modules after modifying requirements.txt
The runpip file is a helper file and has the following commands
. venv/bin/activate pip install -r requirements.txt
Initialize GIT repo and Heroku app
git init git add . git commit -am "init commit" heroku create
PUSHER - Realtime Web Service
Pusher.com is a great way to add realtime events to your webapp.
Register for an account at http://pusher.com/. You will need to create a .env file that includes the following information about your Pusher account.
PUSHER_APP_ID=XXXXXX PUSHER_KEY=XXXXXXXXXXXXX PUSHER_SECRET=XXXXXXXXXXXXXX
Save your .env file.
You will have to push your new .env variables to Heroku config so their servers have your credientals.
In your code directory in Terminal run the following command.
heroku config:add PUSHER_APP_ID=XXXXXX heroku config:add PUSHER_KEY=XXXXXXXXXXXXXXX heroku config:add PUSHER_SECRET=XXXXXXXXXXXXX
Start the Server & Activate the Virtualenv if not already active.
The start file has the following commands
. venv/bin/activate foreman start
If successful you can navigate to http://localhost:5000.