Note that there are some explanatory texts on larger screens.

plurals
  1. PONode.js + socket.io: app on server not working correctly
    primarykey
    data
    text
    <p>I'm new to node.js and socket.io and tried to connect the server to the client with the example from <a href="http://socket.io/#how-to-use" rel="nofollow">http://socket.io/#how-to-use</a>. (no localhost)</p> <p>Server:</p> <pre><code> var app = require('http').createServer(handler) , io = require('socket.io').listen(app) , fs = require('fs') app.listen(80); function handler (req, res) { fs.readFile(__dirname + '/index.html', function (err, data) { if (err) { res.writeHead(500); return res.end('Error loading index.html'+err); } res.writeHead(200); res.end(data); }); } io.sockets.on('connection', function (socket) { socket.on('message', function(msg){ console.log('Got text: '+msg); socket.broadcast.send(msg); }); socket.on('disconnect', function () { }); }); </code></pre> <p>Client:</p> <pre><code>&lt;html&gt;&lt;head&gt;&lt;script src="/socket.io/socket.io.js"&gt;&lt;/script&gt; &lt;script&gt; var socket = io.connect(); socket.on('connect', function () { alert('connected.'); socket.on('message', function (msg) { // my msg alert('message received: '+msg); }); socket.send('hi'); }); &lt;/script&gt; &lt;/head&gt;&lt;body&gt;This is the content :)&lt;/body&gt; &lt;/html&gt; </code></pre> <p>Google Chrome displays in the console:</p> <pre><code>Unexpected response code: 502 </code></pre> <p>Also, after receiving every message, Chrome adds</p> <pre><code>GET http://[myServer]/socket.io/1/?t=1352313105809 socket.io.js:1659 Socket.handshake socket.io.js:1659 Socket.connect socket.io.js:1699 maybeReconnect </code></pre> <p>to the console. Wheres the problem?</p>
    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. 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