Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h1>OLD only use a reference</h1> <h2>Dependencies</h2> <p>uses <a href="http://expressjs.com/">express</a>, <a href="http://socket.io">socket.io</a>, <a href="https://github.com/mranney/node_redis">node_redis</a> and last but not least the <a href="http://www.mediafire.com/?94iz516qwar10ew">sample code</a> from media fire.</p> <h2>Install node.js+npm(as non root)</h2> <p>First you should(if you have not done this yet) install <a href="https://gist.github.com/579814#file_node_and_npm_in_30_seconds.sh">node.js+npm in 30 seconds</a> (the right way because you should <strong>NOT</strong> run npm as <strong>root</strong>):</p> <pre><code>echo 'export PATH=$HOME/local/bin:$PATH' &gt;&gt; ~/.bashrc . ~/.bashrc mkdir ~/local mkdir ~/node-latest-install cd ~/node-latest-install curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1 ./configure --prefix=~/local make install # ok, fine, this step probably takes more than 30 seconds... curl http://npmjs.org/install.sh | sh </code></pre> <h2>Install dependencies</h2> <p>After you installed node+npm you should install dependencies by issuing:</p> <pre><code>npm install express npm install socket.io npm install hiredis redis # hiredis to use c binding for redis =&gt; FAST :) </code></pre> <h2>Download sample</h2> <p>You can download complete sample from <a href="http://www.mediafire.com/?94iz516qwar10ew">mediafire</a>.</p> <h2>Unzip package</h2> <pre><code>unzip pbsb.zip # can also do via graphical interface if you prefer. </code></pre> <h2>What's inside zip</h2> <p><strong>./app.js</strong></p> <pre><code>const PORT = 3000; const HOST = 'localhost'; var express = require('express'); var app = module.exports = express.createServer(); app.use(express.staticProvider(__dirname + '/public')); const redis = require('redis'); const client = redis.createClient(); const io = require('socket.io'); if (!module.parent) { app.listen(PORT, HOST); console.log("Express server listening on port %d", app.address().port) const socket = io.listen(app); socket.on('connection', function(client) { const subscribe = redis.createClient(); subscribe.subscribe('pubsub'); // listen to messages from channel pubsub subscribe.on("message", function(channel, message) { client.send(message); }); client.on('message', function(msg) { }); client.on('disconnect', function() { subscribe.quit(); }); }); } </code></pre> <p><strong>./public/index.html</strong></p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;PubSub&lt;/title&gt; &lt;script src="/socket.io/socket.io.js"&gt;&lt;/script&gt; &lt;script src="/javascripts/jquery-1.4.3.min.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="content"&gt;&lt;/div&gt; &lt;script&gt; $(document).ready(function() { var socket = new io.Socket('localhost', {port: 3000, rememberTransport: false/*, transports: ['xhr-polling']*/}); var content = $('#content'); socket.on('connect', function() { }); socket.on('message', function(message){ content.prepend(message + '&lt;br /&gt;'); }) ; socket.on('disconnect', function() { console.log('disconnected'); content.html("&lt;b&gt;Disconnected!&lt;/b&gt;"); }); socket.connect(); }); &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <h2>Start server</h2> <pre><code>cd pbsb node app.js </code></pre> <h2>Start browser</h2> <p>Best if you start google chrome(because of websockets support, but not necessary). Visit <code>http://localhost:3000</code> to see sample(in the beginning you don't see anything but <code>PubSub</code> as title).</p> <p>But on <code>publish</code> to channel <code>pubsub</code> you should see a message. Below we publish <code>"Hello world!"</code> to the browser.</p> <h2>From ./redis-cli</h2> <pre><code>publish pubsub "Hello world!" </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload