Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I suggest you use Socket.io along side node.js. Install and download the libs from <a href="http://socket.io/" rel="noreferrer">http://socket.io/</a>. You can run it along side your Apache server no problems.</p> <p>First create a node server:</p> <pre><code>var http = require('http') , url = require('url') , fs = require('fs') , io = require('../')//path to your socket.io lib , sys = require(process.binding('natives').util ? 'util' : 'sys') , server; server = http.createServer(function(req, res){ var path = url.parse(req.url).pathname; }), server.listen(8084);//This could be almost any port number </code></pre> <p>Second, run your server from the command line using:</p> <pre><code>node /path/to/your/server.js </code></pre> <p>Third, connect to the socket using client side js:</p> <pre><code>var socket = new io.Socket(null, {port: 8084, rememberTransport: false}); socket.connect(); </code></pre> <p>You will have to have include the socket.io lib client side aswell.</p> <p>Send data from client side to the node server using:</p> <pre><code>socket.send({data:data}); </code></pre> <p>Your server.js should also have functions for processing requests:</p> <pre><code>io.on('connection', function(client){ //action when client connets client.on('message', function(message){ //action when client sends msg }); client.on('disconnect', function(){ //action when client disconnects }); }); </code></pre> <p>There are two main ways to send data from the server to the client:</p> <pre><code>client.send({ data: data});//sends it back to the client making the request </code></pre> <p>and</p> <pre><code>client.broadcast({ data: data});//sends it too every client connected to the server </code></pre>
 

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