Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I also(like Derrish) like to use <a href="http://expressjs.com" rel="nofollow noreferrer">express</a> framework to simplify my work(<strong>AWESOME :)</strong>). You can download and extract this sample from <a href="http://dl.dropbox.com/u/314941/socketio.zip" rel="nofollow noreferrer">http://dl.dropbox.com/u/314941/socketio.zip</a>. I believe you don't even have to install these modules because I have bundled them locally(<strong>just run</strong>) thanks to npm :). </p> <h2>How to install:</h2> <pre><code>alfred@alfred-laptop:~/tmp/socketio$ uname -a Linux alfred-laptop 2.6.35-28-generic #50-Ubuntu SMP Fri Mar 18 19:00:26 UTC 2011 i686 GNU/Linux alfred@alfred-laptop:~/tmp$ wget http://dl.dropbox.com/u/314941/socketio.zip alfred@alfred-laptop:~/tmp$ unzip socketio.zip alfred@alfred-laptop:~/tmp$ cd socketio/ alfred@alfred-laptop:~/tmp/socketio$ node -v v0.4.7 alfred@alfred-laptop:~/tmp/socketio$ npm -v 1.0.6 alfred@alfred-laptop:~/tmp/socketio$ node app.js </code></pre> <h2>The code:</h2> <p><strong>app.js:</strong></p> <pre><code>// npm install express // npm install socket.io var sys = require('sys'), express = require('express'), app = express.createServer('127.0.0.1'), io = require('socket.io'); app.use(express.static(__dirname + '/public')); app.get('/', function (req, res) { res.send('Hello World'); }); app.listen(3000); var socket = io.listen(app); socket.on('connection', function (client){ // new client is here! setTimeout(function () { client.send('Waited two seconds!'); }, 2000); client.on('message', function () { }) ; client.on('disconnect', function () { }); }); </code></pre> <p><strong>public/index.html:</strong></p> <pre><code>&lt;html&gt; &lt;p id="text"&gt;socket.io&lt;/p&gt; &lt;script src="socket.io/socket.io.js"&gt;&lt;/script&gt; &lt;script src="jquery-1.6.1.min.js"&gt;&lt;/script&gt;&lt;!-- Downloaded Jquery --&gt; &lt;script&gt; $(document).ready(function(){ var socket = new io.Socket(), text = $('#text'); socket.connect(); socket.on('connect', function () { text.html('connected'); }); socket.on('message', function (msg) { text.html(msg); }); socket.on('disconnect', function () { text.html('disconnected'); }); }); &lt;/script&gt; </code></pre> <h2>Listing of my modules:</h2> <pre><code>alfred@alfred-laptop:~/tmp/socketio$ npm ls /home/alfred/tmp/socketio ├─┬ express@2.3.11 │ ├── connect@1.4.6 │ ├── mime@1.2.2 │ └── qs@0.1.0 └── socket.io@0.6.18 </code></pre> <h2>Installed modules(NOT necessary):</h2> <pre><code>npm install express npm install socket.io </code></pre> <h2>Browser will display:</h2> <ol> <li><code>socket.io</code> on start, but probably you can't see this because it will be replaced with <code>connected</code>.</li> <li><code>connected</code> when the user connects to socket.io.</li> <li>After 2 seconds it will display <code>Waited two seconds!</code><img src="https://i.stack.imgur.com/gddpD.png" alt="image"></li> </ol>
    singulars
    1. This table or related slice is empty.
    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