I created a virtual machine on Azure and defined a TCP endpoint. I then created a Node.js TCP server as follows:
var net = require('net');
var host = '127.0.0.1';
var port = 8000;
var times = 1;
net.createServer(function (socket) {
console.log('CONNECTED: ' + socket.remoteAddress + ':' + socket.remotePort);
socket.on('data', function (msg) {
console.log("Message received is: " + msg);
if (times == 1)
socket.write("Server says HI");
times++;
executeStatement();
});
socket.on('close', function (data) {
console.log('CLOSED: ' + socket.remoteAddress + ' ' + socket.remotePort);
});
}).listen(port, host);
console.log('System waiting at http://localhost:8000');
I am able to connect to the server while on the same host so two applications on different ports on the same machine can communicate bidirectionally. When I try connecting to the virtual machine through the public IP address and port number, it fails. I tried adding an inbound firewall rule on the virtual machine for the private port (8000) but that also doesn't make a difference. Please, can someone give me some ideas and/or links that help resolve this issue.