开发者

Listening to port that Windows app uses results in EADDRINUSE

I have a Windows application that sends/receives TCP messages on a certain port. I hooked up the simple echo example on the Node.js website but I get the EADDRINUSE error.

I assume this is because my app is using that port.

What I was trying to do开发者_高级运维 is to listen to that port and then hook a browser up to listen to what the server is sending out.


Ok, think I got it working:

var sys = require("sys"),
    net = require("net");

var client = net.createConnection(10100);
client.setEncoding("UTF8");

client.addListener("connect", function() {
  sys.puts("Client connected.");
  // close connection after 2sec
  setTimeout(function() {
    sys.puts("Sent to server: close");
    client.write("close", "UTF8");
  }, 2000);
});

client.addListener("data", function(data) {
  sys.puts("Response from server: " + data);
  if (data == "close") client.end();
});

client.addListener("close", function(data) {
  sys.puts("Disconnected from server");
});


If you want to intercept data sent to and from an applicaiton, I would recommend using Wireshark. If you want to capture this data from an applicaiton, I would recommend you use WinPCap.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜