title: How to make sure only one socket.io connection is open per user?
body: <p>I'm using socket.io and socket.io-client on the Express and React sides, respectively.</p>
  
  <p>On the server side, I console.log in the connection event with the socket.id, and it always displays two connections when I only have one page open, like so:</p>
  
  <p>A user connected woF_Gu_8ElqMB7a5AAAC
  A user connected lBAycJ6j0X5Q469SAAAD</p>
  
  <p>However, when emitting messages from the front end, only one connection is used.</p>
  
  <p>Here's how I set up socket.io server side:</p>
  
  <pre><code>// ** bin/www file **
  var server = http.createServer(app);
  const io = require('socket.io')(server);
  
  // Get socket module and pass it the io socket from here
  require('../sockets')(io);
  
  // ** sockets.js **
  module.exports = io =&gt; {
    io.on('connection', (socket) =&gt; {
      console.log("A user connected", socket.id); // Fires twice with different IDs
  
      socket.on("Setup", data =&gt; {
        console.log("Data received:", data); // Only fires once per emit from frontend
      }
  
      socket.on("disconnect", () =&gt; {
        console.log("User disconnected");
      }
  
  }
  </code></pre>
  
  <p>Here's how I set up client side, though I'm not sure this matters since it's happening consistently even when I don't have this code in:</p>
  
  <pre class="lang-js prettyprint-override"><code>import io from 'socket.io-client';
  const socket = io(window.location.origin);
  </code></pre>
  
  <p>Any idea why I'm getting two connections all the time? Thanks!</p>
  
  <p>EDIT: Adding network screenshot.<a href="https://i.stack.imgur.com/SQT8m.png" rel="noreferrer"><img src="https://i.stack.imgur.com/SQT8m.png" alt="enter image description here"></a></p>