I’m working on a test harness that interacts with another node application and verifies that the other application works properly. I need to be able to listen to two different protocols, on two different ports, in the same process in node.js. Specifically, I am intercepting a simple line-break text protocol (acceptorone) and HTTP requests (acceptortwo).
I currently have this:
var acceptorone = net.createServer();
acceptorone.listen(portone);
var acceptortwo = http.createServer();
acceptortwo.listen(porttwo);
Yet when I try this I get Error: listen EADDRINUSE. Both codepaths work fine independently, everything is fine if one of the listen()s is commented out.
Googling around a bit yields a solution that involves forking off several processes. However, this is running in a test framework so I need to keep everything inside the same process. Applications such as statsd have no qualms accepting TCP and UDP connections simultaneously, so I’m not sure why there would be a limitation on listening on multiple TCP sockets at the same time. Can anyone shed light on the issue? Thanks.
I think something else must be broken with your example; can you show how you initialize
portoneandporttwo?