Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think what you need is to <a href="https://github.com/LearnBoost/Socket.IO/wiki/Configuring-Socket.IO" rel="nofollow">configure</a> <code>socket.io</code> <code>client</code> to not <code>reconnect</code> is set property <code>reconnect</code> to <code>false</code></p> <p>I created a little server(<code>server.js</code>) to test this:</p> <pre><code>var io = require('socket.io').listen(8888); io.sockets.on('connection', function (socket) { socket.emit('news', { hello: 'world' }); socket.on('my other event', function (data) { console.log(data); }); }); </code></pre> <p>Then I created this <code>test.js</code> to test that it does not reconnect</p> <pre><code>var client = require('socket.io-client'), socket = client.connect('http://localhost:8888', { 'reconnect': false }); socket.on('connect', function () { socket.on('news', function (data) { console.log(data); socket.emit('my other event', { my: 'data' }); }); }); </code></pre> <p>For <code>test.js</code> to work you will need to install <code>socket.io-client</code> from <code>npm</code> issuing <code>npm install socket.io-client</code> or by adding <code>socket.io-client</code> (dev-)<code>dependency</code> to your <code>package.json</code>.</p> <p>When I stop <code>server.js</code> while <code>test.js</code> is running <code>test.js</code> will return immediately which I believe is your desired result. When I set <code>reconnect</code> to <code>true</code> the client will try to reconnect to server which is not the desired behaviour</p>
 

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