Forward request to ws client and wait for response Express

前端 未结 3 1891
抹茶落季
抹茶落季 2020-12-22 11:41

I\'m trying to build an endpoint that will receive a request, emit the request data to a WebSocket client, wait for an event, then send back the response using express + soc

3条回答
  •  無奈伤痛
    2020-12-22 12:14

    Please note that:

    socket.on('res', function (data) {
        res.status(200).json(data);
    });
    

    Is being called each time a socket is sending a response, thus showing the above error. You should unbind the listener inside the callback function.

提交回复
热议问题