Is there a way to get the response for a specific emit using socket.io?
<p>I need to perform GET requests on a server that doesn't have a CORS header, so I created a very simple node app that will do the GET for me:</p>

<pre><code>var io = require('socket.io')();
var request = require('request');

io.on('connection', function(socket) {
  socket.on('get', function(url) {
    request(url, function(error, response, body) {
      socket.emit('response', body);
    });
  });
});
</code></pre>

<p>On the client side, I'm using it with a simple <code>get</code> function:</p>

<pre><code>var socket = io();

function get(url) {
  return new Promise(function(resolve) {
    socket.emit('get', url);
    socket.once('response', function(data) {      
      resolve(data);
    });
  }
}
</code></pre>

<p>This works great when I request a URL one at a time:</p>

<pre><code>get('http://some/resource/1');
</code></pre>

<p>But when I try multiple requests to different endpoints at the same time, they will all return the same data:</p>

<pre><code>get('http://some/resource/1');
get('http://some/resource/2');
get('http://some/resource/3');
</code></pre>

<p>In this case, the data for <code>/resource/1</code> is returned for all 3. I understand that this is because the <code>socket.once('response')</code> callback is getting added immediately for all 3 requests, and when the data is returned for the first one, all 3 callbacks are invoked for it.</p>

<p>Is there a way that I can get it so that each <code>socket.emit()</code> and <code>socket.on()</code> are paired to each other? I know that I can add a unique ID to each emit and pass it back on the response, or use the unique ID in the message itself (something like <code>socket.emit('get:a54jk14hf')</code>, but I'm hoping for a simpler solution if there is one.</p>