Note that there are some explanatory texts on larger screens.

plurals
  1. PONodeJS + socket.io: simple Client/Server example not working
    primarykey
    data
    text
    <p>I’m using NodeJS v0.4.8 and the latest Version of socket.io from</p> <blockquote> <p>npm install socket.io</p> </blockquote> <p>on Ubuntu:</p> <blockquote> <p>Linux mars 2.6.38-8-generic #42-Ubuntu SMP Mon Apr 11 03:31:50 UTC 2011 i686 i686 i386 GNU/Linux</p> </blockquote> <p>The following code unfortunately doesn't produce any output, wheter on client, nor on server side.</p> <p>Does anybody have a clue?</p> <h2>SERVER-SIDE</h2> <pre><code>var http = require('http'), io = require('socket.io'), fs = require('fs'), sys = require('sys'); respcont = fs.readFileSync('testclient.js'); server = http.createServer(function(req, res){ res.writeHead(200, {'Content-Type': 'text/html'}); res.end(respcont); }); server.listen(8082); var socket = io.listen(server); socket.on('connection', function(client){ sys.puts("New client is here!"); client.send("hello world"); client.on('message', function(msg) { sys.puts("client has sent:"+msg); }) ; client.on('disconnect', function() { sys.puts("Client has disconnected"); }) ; }); </code></pre> <h2>CLIENT-SIDE</h2> <pre><code>&lt;html&gt; &lt;body&gt; &lt;script type="text/javascript" src="http://localhost:8082/socket.io/socket.io.js"&gt;&lt;/script&gt; &lt;script&gt; var socket = new io.Socket(null,{port:8082,rememberTransport:true,timeout:1500}); socket.connect(); socket.on('connect', function() { console.log('connected to server'); socket.send('Hi Server...'); }); socket.on('message', function() { console.log('received a message!'); }); socket.on('disconnect', function() { console.log('disconnected from server'); }); &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>The output from NodeJS (NOT the sys.puts("...") calls) is:</p> <blockquote> <p>info - socket.io started debug - served static /socket.io.js debug - client authorized info - handshake authorized info - handshaken b61a5c2751c1c8c8493db4b79d19e779</p> </blockquote>
    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.
 

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