Note that there are some explanatory texts on larger screens.

plurals
  1. POPrevent favicon.ico from making a second request - Node.js
    primarykey
    data
    text
    <p>I'm trying to prevent <strong>favicon.ico</strong> form making a second request when a socket connects. </p> <p>Here is my server:</p> <pre><code>var io = require('socket.io'), connect = require('connect'); var app = connect() .use(connect.static('public')) .use(function(req, res, next){ if (req.url === '/favicon.ico') { res.writeHead(200, {'Content-Type': 'image/x-icon'} ); next(); } }) .use(function(req, res){ res.end('stupid favicon...'); }).listen(3000); var game = io.listen(app); game.sockets.on('connection', function(socket){ socket.emit('entrance', {message: 'Welcome to the game!'}); socket.on('disconnect', function(){ game.sockets.emit('exit', {message: 'A player left the game...!'}); }); game.sockets.emit('entrance', {message: 'Another gamer is online!'}); }); </code></pre> <p>This does not seem to work. I get no errors, but when one socket connects, two images is loaded from the client side, which makes it seem like there is still two requests happening. </p> <p>So is my code completely wrong, or am I on the right track? Because no matter what I <code>console.log()</code> in my server-code, nothing is printed to the console.</p> <p><strong>EDIT: Client side</strong></p> <pre><code>var socket = io.connect('http://localhost:3000'); socket.on('entrance', function(data){ console.log(data.message); var num = (count &gt; 0) ? count : ''; console.log("hero" + num); var hero = new Car("hero" + num); hero.init(); count++; }); </code></pre> <p><code>count</code> is global. I have (for now two images), one <code>#hero</code> and <code>#hero1</code>. When one player connects both images are loaded. </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.
 

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